我已经看过关于 的官方MSDN文档DependencyProperty.RegisterAttached
,但是,它似乎并没有表明这个问题暗示的这个必需的命名约定
我知道代码必须是这样的:
public static readonly DependencyProperty HandleKeyPressEventProperty =
DependencyProperty.RegisterAttached("HandleKeyPressEvent",
typeof(bool),
typeof(MyDataGrid),
new UIPropertyMetadata(true));
public static bool GetHandleKeyPressEvent(DependencyObject obj)
{
return (bool)obj.GetValue(HandleKeyPressEventProperty);
}
public static void SetHandleKeyPressEvent(DependencyObject obj, bool value)
{
obj.SetValue(HandleKeyPressEventProperty, value);
}
在这种情况下,是否需要 Get 和 Set 方法来保留该名称?附加财产是否必须以“财产”结尾?另外,我可以让我的代码变成这样:
public static readonly DependencyProperty HandleKeyPressEventProperty =
DependencyProperty.RegisterAttached("FooEvent", //change registered name
typeof(bool),
typeof(MyDataGrid),
new UIPropertyMetadata(true));
public static bool GetHandleKeyPressEvent(DependencyObject obj)
{
return (bool)obj.GetValue(HandleKeyPressEventProperty);
}
public static void SetHandleKeyPressEvent(DependencyObject obj, bool value)
{
obj.SetValue(HandleKeyPressEventProperty, value);
}
谁能弄清楚这个“神奇”的命名方案以及我必须遵循什么样的标准?