Suppose having this kind of CLR-objects:
public class Foo
{
...
public Bar { get; private set; }
}
public class Bar: INotifyPropertyChanged
{
public string Baz { get {...} set {...} }
}
Now I have a Window, with the DataContext bound to an instance of Foo. Within this Window I do:
<TextBox Text={Binding Bar.Baz} />
Because Foo doesn't implement INotifyPropertyChanged, I'll get a well known WPF memory leak here. There are two solutions:
- Implement INotifyPropertyChange on
- Foo Use a OneTime binding
I don't like 1), so let's say, we want to use a OneTime binding. But I only need the OneTime binding for accessing Bar while I need TwoWay binding for Baz:
<TextBox DataContext="{Binding Bar, Mode=OneTime}" Text={Binding Baz, Mode=TwoWay} />
So far so good, but if some other property from TextBox now needs to be bound to a property of Foo, things get complicated, because the DataContext isn't the Foo instance anymore.
So here's the question: Is there a way to specify a Bindig (in XAML or Code) that binds OneTime to a parent property and TwoWay to a child property?