The TreeView class offers:
[System.ComponentModel.Bindable(true)]
public object SelectedItem { get; }
I tried to code a Binding in XAML and in C# with a Binding mode OneWayToSource. My code in the viewmodel looks like this:
Binding Binding = new Binding();
Binding.Mode = BindingMode.OneWayToSource;
Binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
Binding.Source = this;
Binding.Path = new PropertyPath( "SelectedItem" );
Binding.NotifyOnSourceUpdated = true;
var bindingExpression = BindingOperations.SetBinding( MainView.LoadTree, TreeView.SelectedItemProperty, Binding );
The last line ends with a SystemArgumentException "'SelectedItem' property cannot be data-bound. Parameter name: 'dp'".
AFAIK this is due to the code in the Binding.CreateBindingExpression method, which checks at start, whether the DP is readonly and throws that exception if true. Because the Binding is OneWayToSource this is no violation of the "readonly" tag of SelectedItem.
Any help is very welcome.