在我再次运行下面的代码之前,如何知道是否已注册“Status”DependencyProperty?
代码:
public readonly DependencyProperty StatusProperty ;
public string Status
{
get { return (string)GetValue(StatusProperty); }
set { SetValue(StatusProperty, value); }
}
StatusProperty = DependencyProperty.Register("Status", typeof(string), typeof(CWindow), new PropertyMetadata());
答案 0 :(得分:0)
您需要反思才能找到已注册的依赖项属性。
using System.Reflection;
foreach (FieldInfo fInfo in CWindow.GetType().GetFields())
{
if (fInfo.FieldType.Name == "DependencyProperty")
{
if (fInfo.GetValue(null) == "Status")
{
Console.WriteLine("Status Property already Registered");
}
}
}