WPF如何绑定到集合中的特定元素 [英] WPF How to bind to a specific element in the Collection

查看:116
本文介绍了WPF如何绑定到集合中的特定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绑定到集合中的特定元素
但是我不知道如何编写绑定。
这是代码:

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

谢谢

推荐答案

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

这篇关于WPF如何绑定到集合中的特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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