views:

592

answers:

2

Hello,

I'm trying to bind a Dependency Property from my UserControl to my MainViewModel.

This is how the DependencyProperty looks like:

    public static DependencyProperty ItemHasChangesProperty = DependencyProperty.Register("ItemHasChanges",
                                                                                  typeof(bool),
                                                                                  typeof(MyUserControl),
                                                                                  new PropertyMetadata(null));
    public bool ItemHasChanges
    {
        get { return (bool)GetValue(ItemHasChangesProperty); }
        set { SetValue(ItemHasChangesProperty, value); }
    }

My XAML:

  <local:MyUserControl ItemHasChanges="{Binding Path=Changes}" Grid.Row="4"   />

Now when debugging and checking the Set-Accessor of "bool Changes", I see that it never gets accessed when I set in the UserControl ItemHasChanges = true;

Any idea what I'm doing wrong here?

Thanks!

Cheers

A: 

Are you setting ItemHasChanges on the control directly (as in, not by updating the binding source)? If so, that will remove the binding.

Richard Szalay
No I'm binding the Source to the Control and depending on a Action, I change the Value of the Source..
Joseph Melettukunnel
+2  A: 

Got it.. I had to change

<local:MyUserControl ItemHasChanges="{Binding Path=Changes}" Grid.Row="4"   />

to

<local:MyUserControl ItemHasChanges="{Binding Path=Changes, Mode=OneWayToSource}" Grid.Row="4"   />

Took me about 3h to figure it out.. haha :-)

Cheers

Joseph Melettukunnel