I have WPF application and a window in it. Lets have something like this in my xml:
Here's how you define and apply a binding in code:
Binding binding = new Binding {
Source = TitleLabel,
Path = new PropertyPath("Content"),
};
BottomLabel.SetBinding(ContentControl.ContentProperty, binding);
Note that on objects that don't derive from FrameworkElement
, you have to explicitly use BindingOperations.SetBinding()
instead of element.SetBinding()
:
BindingOperations.SetBinding(BottomLabel, ContentControl.ContentProperty, binding);