Binding to a sub-property
I built a struct named Fraction, with three properties: double Value, int Numerator and int Denominator. In my data source I use the Fraction as a property, Fraction Position.
The data is bound li开发者_Go百科ke this:
<TextBox Text="{Binding Path=Position.Numerator}"/>
<TextBox Text="{Binding Path=Position.Denominator}"/>
but the binding happens to work only one way - from source to target. I tried to catch the SourceUpdated event, but it didn't work.
Is there a way to force two-way binding? I tried Mode=TwoWay, but it didn't work either.
You may have to create Position
as a dependency property so that when target updates source updates too
Edit
please check it should be something like
public static readonly DependencyProperty PositionProperty = DependencyProperty.Register("Position", typeof(Fraction), typeof(NoteUserControl),new UIPropertyMetadata(new Fraction()));
public Fraction Position
{
get { return (Fraction)GetValue(PositionProperty ); }
set
{
SetValue(PositionProperty, value);
}
}
Hope NoteUserControl is the Class in which you have defined the dependency property
精彩评论