我有以下类架构
public Class Test : DependencyObject
{
private DependencyProperty _thickness = DependencyProperty.Register("Thickness", typeof(double), typeof(CounterDataStreamWrapper));
public double Thickness
{
get
{
return (double)GetValue(this._thickness);
}
set
{
SetValue(this._thickness, value);
}
}
... Rest of the code
}
基本上我有一组Test对象,我想将每个的Thickness值绑定到相应的UI元素。我对C#绑定不太熟悉。当我尝试创建多个对象时,我遇到“DependencyProperty已经注册”问题。我确信我只是缺少一些绑定到DependencyProperty的关键概念。
感谢任何帮助!
答案 0 :(得分:4)
您正在CounterDataStreamWrapper类型和private per instance上注册Thickness DependencyProperty。
将DependencyProperty设为public static并将其注册为Test类。
public static DependencyProperty Thickness =
DependencyProperty.Register("Thickness", typeof(double), typeof(Test));
答案 1 :(得分:3)
它应该是静态的。像这样:
private static DependencyProperty _thickness ...