【问题标题】:How can I bind certain properties belonging to a custom control?如何绑定属于自定义控件的某些属性?
【发布时间】:2009-03-03 17:21:20
【问题描述】:

如果我有以下控制:

public partial class MyControl : UserControl{
    public string MyControlText{
        get { return MyTextBox.Text; } 
        set { MyTextBox.Text = value; }
    }

    public MyControl(){ ... }
}

当我将控件放在我的一个页面上时,如何绑定到“MyControlText”属性,如下所示:

<local:MyControl MyControlText={Binding Path=SomeField} />

谢谢!

【问题讨论】:

    标签: c# .net wpf data-binding custom-controls


    【解决方案1】:

    您需要将该属性设为依赖属性。 DependencyProperty 类的文档向您展示了如何执行此操作:

    http://msdn.microsoft.com/en-us/library/system.windows.dependencyproperty.aspx#

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-11
      • 2012-08-29
      • 2011-06-24
      • 2011-03-20
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      相关资源
      最近更新 更多