【发布时间】:2012-07-20 19:43:46
【问题描述】:
我有一个 C# 自定义 WPF 控件。我在控件上有基于 DependencyProperty 的属性。
public static readonly DependencyProperty CurrentStateProperty =
DependencyProperty.Register( "CurrentState", typeof(ControlStateEnum),
typeof(MyCustomControl), new PropertyMetadata(ControlStateEnum.Started));
public ControlStateEnum CurrentState
{
get { return (ControlStateEnum) GetValue(CurrentStateProperty); }
set { SetValue(CurrentStateProperty, value); }
}
现在,如果我使用控件,并尝试使用它,唉:
<myControls:MyCustomControl CurrentState="Loaded" />
CurrentState 永远不会设置为“已加载”并保持“已启动”。我想让它能够绑定,但也能够在没有绑定的情况下设置......有什么我不明白或遗漏的东西吗?
当我在设置器上设置断点时,它不会在窗口加载时更新。
【问题讨论】:
-
因此,在控件初始化和加载之后,最终值是从 XAML 设置在控件上的。所以处理它的方法是在DependencyProperty上添加一个PropertyChangedHandler。感谢您帮助诊断它,parapura。
标签: c# wpf dependency-properties