Software Data Binding

How do you do this in C #?

<TextBlock Text={Binding MyProperty}/> 

Suppose the DataContext is set to the Type MyClass class

+4
source share
3 answers

You can call FrameworkElement.SetBinding () to create data binding with C #.

+2
source

Assuming your TextBlock is called _textBlock :

 var binding = new Binding("MyProperty"); BindingOperations.SetBinding(_textBlock, TextBlock.TextProperty, binding); 
+6
source

Plain:

 <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.

+2
source

Source: https://habr.com/ru/post/1286082/


All Articles