【发布时间】:2017-11-17 20:22:46
【问题描述】:
所以我创建了一个用户控件,并在其上创建了一个依赖属性 TestProperty。
我想拥有此用户控件的 2 个实例,并将每个实例的 TestProperty 设置为不同的值。
<widgets:mycontrol Test="val1"></widgets:WTComboBox>
<widgets:mycontrol Test="val2"></widgets:WTComboBox>
如果我将 testproperty 创建为静态 DependencyProperty,如下所示:
public static readonly DependencyProperty TestProperty=
DependencyProperty.Register("Test", typeof(string), typeof(mycontrol), null);
在控件中,那么显然我不能在每个实例中为其设置不同的值,但是当我将 testproperty 创建为普通实例属性时
public DependencyProperty TestProperty;
public mycontrol()
{
TestProperty = DependencyProperty.Register("Test", typeof(string), typeof(mycontrol), null);
}
在控件上,则设计人员无法识别该属性存在并创建错误,但在运行时该控件可以正常工作,并且该控件的每个实例都具有测试属性的正确值。
所以问题是如何让实例依赖属性在设计器中工作?
谢谢
【问题讨论】:
标签: c# xaml uwp dependency-properties