【发布时间】:2017-05-17 14:49:58
【问题描述】:
好的,所以我有一个源自 Panel 的测试控件。我向它添加了新的依赖属性。
public class TestPanel : Panel
{
public static DependencyProperty TestProperty = DependencyProperty.Register(
"Test",
typeof(double),
typeof(TestPanel),
new FrameworkPropertyMetadata(
0.0,
null));
public double Test
{
get
{
return (double)this.GetValue(TestProperty);
}
set
{
this.SetValue(TestProperty, value);
}
}
}
然后我在 xaml 中定义了它<controls:TestPanel Test="50" />
但现在我想知道,为什么不调用 Test 的设置器?它不应该传递值(50)吗?在排列过程中我得到默认值(0.0)。
还是仅使用绑定才有效?
【问题讨论】:
-
WPF 直接调用 SetValue。所以你的setter不会被执行。但是控件初始化后的测试值应该是 50。你在任何地方都读过这个值吗?
-
是的,我的依赖属性不匹配,重复也指向我的扩展信息,谢谢
标签: c# wpf dependency-properties