与ListBox.Items定制绑定控件属性 [英] Bind custom control property with ListBox.Items

查看:154
本文介绍了与ListBox.Items定制绑定控件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My custom control has the following basic structure:

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

和XAML中我有:

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

绑定不会在这种情况下工作。是属性项目错了?

推荐答案

您绑定是不正确的。使用的ElementName 属性的结合来告诉WPF到哪里找数据,然后绑定到项目属性

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}" />

这篇关于与ListBox.Items定制绑定控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆