I used additional attributes when writing programs today. I used VS built-in propa code snippet, the code is as follows:
class Attach { public static bool GetIsEnabled(DependencyObject obj) { return (bool)(IsEnabledProperty); } public static void SetIsEnabled(DependencyObject obj, bool value) { (IsEnabledProperty, value); } public static readonly DependencyProperty IsEnabledProperty = ("IsEnabled", typeof(bool), typeof(Attach), new PropertyMetadata(false)); }
The methods used in XAML are as follows:
<Grid local:="true" x:Name="grid" />
However, when debugging, I found a problem: although there is no problem in reading and writing the value of the additional attribute, it is logical that the function should be called once at startup, but the breakpoint cannot be broken. When adding callback notifications for property changes, the callback function can also run normally.
I found some sample code online and found that some breakpoints can be broken into the Set function, but some cannot. Then I compared the sample code with my code one by one, and finally found that just add a "Property" to the name of the registered additional property. Change to as follows
class Attach { public static bool GetIsEnabled(DependencyObject obj) { return (bool)(IsEnabledProperty); } public static void SetIsEnabled(DependencyObject obj, bool value) { (IsEnabledProperty, value); } public static readonly DependencyProperty IsEnabledProperty = ("IsEnabledProperty", typeof(bool), typeof(Attach), new PropertyMetadata(false)); }
At first I thought there was something wrong with the code snippet provided by VS, which caused me to generate the wrong code, so I went to MSDN to check it out and found that the MSDN sample code page also did not have the "Property" suffix (address:Additional attribute overview). In other words, the orthodox form is the automatic generation without the "Property" suffix. Although the execution results of both forms are the same, there is definitely a problem with the default behavior of not using the Set function for the first time.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.