Use the constructor of
Binding
and set the source manually:
var binding = new Binding();
binding.Source = myObject;
The Path-property specifies the property of the source.
Optionally myObject implements INotifyPropertyChanged, so changes are updated automatically.
With
BindingOperations.SetBinding
you can set this Binding for a
DependencyObject
:
BindingOperations.SetBinding(this, ContentControl.ContentProperty, binding);
Bindings only work with a
DependencyObject
as target, the source can be anything.
If you want to bind a DependencyObject to an object (i.e. the other way round), set
Mode
to
BindingMode.OneWayToSource