Binding String Property in Code-Behind TextBlock

Use BindingOperations

Binding binding = new Binding();
binding.Path = new PropertyPath("SomeText");
binding.Source = sourceObject;  // view model?

BindingOperations.SetBinding(theTextBlock, TextBlock.TextProperty, binding);

Leave a Comment