基于每个对象绑定到dependencyproperty

本文关键字:dependencyproperty 绑定 对象 于每个 | 更新日期: 2024-09-21 16:38:51

我有以下类模式

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的关键概念。

感谢您的帮助!

基于每个对象绑定到dependencyproperty

您正在注册CounterDataStreamWrapper类型的Thickness DependencyProperty和private per instance。

将DependencyProperty设置为public static,并为类Test注册它。

public static DependencyProperty Thickness = 
    DependencyProperty.Register("Thickness", typeof(double), typeof(Test));

它应该是静态的。像这样:

private static DependencyProperty _thickness ...
相关文章:
  • 没有找到相关文章