Bind custom control property with ListBox.Items

守給你的承諾、 提交于 2019-12-25 00:17:34

问题


My custom control has the following basic structure:

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

And in XAML I have:

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

The bind doesn't work in this case. Is the property Items wrong?


回答1:


Your binding is incorrectly. Use the ElementName property in your binding to tell WPF where to look for the data, then bind to the Items property

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


来源:https://stackoverflow.com/questions/11435181/bind-custom-control-property-with-listbox-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!