簡體   English   中英

將自定義控件屬性與ListBox.Items綁定

[英]Bind custom control property with ListBox.Items

我的自定義控件具有以下基本結構:

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

在XAML中,我有:

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

綁定在這種情況下不起作用。 財產Items錯了嗎?

您的綁定錯誤。 在綁定中使用ElementName屬性告訴WPF在哪里尋找數據,然后綁定到Items屬性

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM