Reputation: 15378
How correct add PropertyPath ?
I need binding usercontrol DataContext to DataContext, TwoWay.
var binding = new Binding()
{
Mode = BindingMode.TwoWay,
Source = ((FrameworkElement)sender),
Path = new PropertyPath(FrameworkElement.DataContextProperty)
};
binding.Source = ((FrameworkElement) sender);
changeImage.SetBinding(FrameworkElement.DataContextProperty, binding);
Upvotes: 1
Views: 4688
Reputation: 70162
PropertyPath
has a string consructor, which takes the property path as follows:
var binding = new Binding()
{
Mode = BindingMode.TwoWay,
Source = ((FrameworkElement)sender),
Path = new PropertyPath("DataContext")
};
Alternatively, Binding
has a constructor which will create a PropertyPath
from the gives string argument:
var binding = new Binding("DataContext")
{
Mode = BindingMode.TwoWay,
Source = ((FrameworkElement)sender)
};
Upvotes: 1
Reputation: 17274
binding.Path = new PropertyPath("DataContext")
Also it would help if you will say what is wrong with your code.
Upvotes: 3