我有一个 DependencyObject(一种交互行为),我想从代码中获取它的 x:Name(只是获取,而不是设置)。可能吗?
编辑:按照 AnthonyWJones 的回答:
我已将以下代码插入到我的基本行为中:
[EditorBrowsable(EditorBrowsableState.Never)]
public string Name
{
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register("Name", typeof(string), typeof(BaseBehavior<T>), new PropertyMetadata(null));
我已经给出了我的行为 x:Name,但 Name 属性没有被填充。