c# - How to set The DataContext of a TextBlock to class at XAML -


i want set datacontext of textblock @ xaml.

resharper suggested this

<textblock text="{binding name}" margin="50" d:datacontext="{d:designdata class1}" /> 

but when run application reason textblock has datacontext class specified @ view's code-behind , displays wrong text

views's code-behind

    public partial class viewa : usercontrol {     public viewa() {         initializecomponent();         vmb vm = new vmb();         datacontext = vm;     } } 

so want display class1 name property instead of vmb name property.

d:datacontext sets datacontext visual designer only. if want bind class need set actual datacontext instance of class1. instance , how set you.


Comments