WPF Getter/Setter Not Being Called

后端 未结 3 1439
感情败类
感情败类 2020-12-04 00:56

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

相关标签:
3条回答
  • 2020-12-04 01:07

    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.

    0 讨论(0)
  • 2020-12-04 01:18

    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.

    0 讨论(0)
  • 2020-12-04 01:20

    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.

    0 讨论(0)
提交回复
热议问题