C # / WPF: Dependency property not updating related property?

I am trying to associate the Dependency property from my UserControl with my MainViewModel.

This is what 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 that I have debugged and checked the Set-Accessor "bool Changes", I see that it never gets access when I set in UserControl ItemHasChanges = true;

Any idea what I'm doing wrong here?

Thanks!

Greetings

+4
source share
2 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 3 hours to figure it out. haha :-)

Greetings

+9
source

Are you setting ItemHasChanges in the control directly (as in, rather than updating the binding source)? If so, this will remove the binding.

0
source

All Articles