简体   繁体   English

WPF如何绑定到集合中的特定元素

[英]WPF How to bind to a specific element in the Collection

I want to make a binding to a specific element in the Collection . 我想绑定到Collection中的特定元素 But I cannot figure out how to write the Binding. 但是我不知道如何编写绑定。 This is the code: 这是代码:

public class MySource
{
 ..
 public string SomeProp;
 public ICollection<T> MyCollection;
 ..
}

this.DataContext = new MySource();

<TextBox Text={Binding SomeProp} />

<TextBox Text={Binding FIRST_ELEMENT_OF_THE_MyCollection} />
<TextBox Text={Binding SECOND_ELEMENT_OF_THE_MyCollection} />
<!--Ignore other elements-->

Try to replace those binding strings, please 请尝试替换那些绑定字符串

Thank you 谢谢

<TextBox Text="{Binding MyCollection[0]}" /> 
<TextBox Text="{Binding MyCollection[1]}" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM