WPF How to bind to a specific element in the Collection

痴心易碎 提交于 2019-12-25 03:15:54

问题


I want to make a binding to a specific element in the 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


回答1:


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


来源:https://stackoverflow.com/questions/2854956/wpf-how-to-bind-to-a-specific-element-in-the-collection

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