How can I make a two way binding in code behind between one dependency property in window and another one in a UserControl, so that when user action in one will update the DP in another
public partial class MyWindow
{
public MyWindow()
{
InitializeComponent();
var myControl = new MyControl();
this.SetBinding(MyWindow.CurrentPathProperty, new Binding
{
Source = myControl.CurrentPath
});
}
public string CurrentPath
{
get { return (string)GetValue(CurrentPathProperty); }
set { SetValue(CurrentPathProperty, value); }
}
public static readonly DependencyProperty CurrentPathProperty =
DependencyProperty.Register("CurrentPath", typeof(string),
typeof(MyWindow), new PropertyMetadata(OnPathChanged));
}
public partial class MyControl : UserControl
{
public string CurrentPath
{
get { return (string)GetValue(CurrentPathProperty); }
set { SetValue(CurrentPathProperty, value); }
}
public static readonly DependencyProperty CurrentPathProperty =
DependencyProperty.Register("CurrentPath", typeof(string),
typeof(MyControl), new PropertyMetadata(OnPathChanged));
}