The problem I am having is probably very simple to solve, yet it seems tricky from beginner’s perspective.
I created 2 windows visible simultaneously, one with ListBox on it, another with TextBox. I would like to bind window1.ListBox.SelectedValue to window2.TextBox.Text property programmatically. I am not using value converters.
The code is straightforward:
var binding = new Binding("SelectedValue");
binding.Source = window1.ListBox;
// binding.Path = new PropertyPath(ListBox.SelectedValueProperty);
var bound = window2.TextBox.SetBinding(TextBlock.TextProperty, binding);
I would like to bind using DependencyProperty instance instead of property name for performance reasons, but I also tried binding by name. Binding just does not work.
You can download dummy VS2010 project here.
This leads to another question – how to debug binding, which event (if any) to subscribe to detect Binding changes ?
Problem solved – I mistakenly called SetBinding with a TextBlock.TextProperty, when it should be TextBox.TextProperty.