tags:

views:

15

answers:

1

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 like 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.

A: 

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

ajay_whiz
I added this line: public static readonly DependencyProperty PositionProperty = DependencyProperty.Register("Position", typeof(Fraction), typeof(NoteUserControl)); and the binding stopped working at all!
gideonrv
@gideonrv please see the Edit
ajay_whiz
I tried it, with UIPropertyMetadata and without it, but it still doesn't work. I hope that, as a musician, you'd like to see my project. Its a MIDI pianoroll. Please send hello to [email protected].
gideonrv
@gideonrv mail sent
ajay_whiz