How how do you do this in c#?
<TextBlock Text={Binding MyProperty}/>
Assume the DataContext is set to a class of Type MyClass
How how do you do this in c#?
<TextBlock Text={Binding MyProperty}/>
Assume the DataContext is set to a class of Type MyClass
You can call FrameworkElement.SetBinding() to build data binding from C#.
Assuming your TextBlock
is called _textBlock
:
var binding = new Binding("MyProperty");
BindingOperations.SetBinding(_textBlock, TextBlock.TextProperty, binding);
HTH, Kent
Simple:
<TextBlock x:Name="txt"/>
// C#
txt.SetBinding(TextBox.TextProperty, "MyProperty");
Create a Binding object and pass it to SetBinding if you want more control over the binding.