Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#/WPF: Dependency Property is not updating the bound Property?

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

like image 489
Joseph jun. Melettukunnel Avatar asked Dec 14 '09 14:12

Joseph jun. Melettukunnel


1 Answers

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

like image 179
Joseph jun. Melettukunnel Avatar answered Sep 18 '22 22:09

Joseph jun. Melettukunnel