【问题标题】:Bind custom control property with ListBox.Items将自定义控件属性与 ListBox.Items 绑定
【发布时间】:2012-07-11 05:17:11
【问题描述】:

我的自定义控件具有以下基本结构:

public class NewTextBox : TextBox
{
    public ItemCollection Items { get; set; }
}

在 XAML 中我有:

<ListBox Name="listBox1" />
<my:NewTextBox Items="{Binding Path=listBox1.Items}" />

在这种情况下绑定不起作用。属性Items错了吗?

【问题讨论】:

  • 我试过这个 link 和这个 link 也没有帮助。

标签: c# wpf xaml binding user-controls


【解决方案1】:

您的绑定不正确。在绑定中使用ElementName 属性告诉WPF 在哪里查找数据,然后绑定到Items 属性

<my:NewTextBox Items="{Binding ElementName=listBox1, Path=Items}" />

【讨论】:

  • 谢谢,瑞秋。它可以工作,但我必须修改属性以包含 DependencyProperty。
猜你喜欢
  • 1970-01-01
  • 2011-05-11
  • 2014-09-21
  • 2011-08-29
  • 2011-06-22
  • 2013-12-25
  • 1970-01-01
  • 2012-08-07
相关资源
最近更新 更多