I have the following code. The PropertyChanged event is being called but the getter and setter is not. I can\'t for the life of me see why not. I have other properties where
XAML will invoke the SetValue
and GetValue
methods directly, which is why you shouldn't place any logic in your static Set
/Get
methods, but use a property changed handler instead.
I've found the reason why the getters and setters didn't appear to be firing. In my placement dependency property, I was setting the default value to PlacementMode.Right. WPF is ignoring the default value. I was then setting it to Placement="Right" in the XAML. Because this value was the same as the default, it was again ignored. By changing the default value to PlacementMode.Relative, I can now successfully set the value to "Right" in the XAML. This does prevent me from using Relative if I want, but I guess that could be solved by converting my properties to an object, which would then have a default of null.
The Setter
and Getter
are only the .NET Wrappers for your coding. When Binding from XAML the GetXXXX
and SetXXX
will be called and not the Property Getter
and Setter
.
You can also access the DependencyProperty
PropertyChanged
Callback, this function will be called everytime the Property is changed.