将一个列表框listboxitem与另一个列表框绑定 [英] Binding one listbox listboxitem from another listbox

查看:74
本文介绍了将一个列表框listboxitem与另一个列表框绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C#WPF很新,所以请耐心等待我的问题。我有两个列表框(listbox1和listbox2),其中listbox1中的项目将在运行时通过用户输入添加或删除。我希望listbox2通过绑定方法相应地显示其listboxitem。



例如,如果listbox1最初有5个项目,我希望listbox2显示相同的5个项目。如果在运行时添加或删除listbox1中的项目,我希望listbox2显示与listbox1相同的数据(项目)。



有人可以给我一个提示吗?在此先感谢。

解决方案

这是jaideepsinh所说的并将它们与原始数据绑定在一起。或者你将listbox2绑定到listbox1就像这样



 <   ListBox    名称  =  listbox1    ItemsSource   =  {Binding yourdatasource} >  
< / ListBox >
< ListBox ItemsSource = {Binding ElementName = listbox1,Path = ItemSource} >
< / ListBox >


I am pretty new to C# WPF, so please bear with my question. I have two listboxes (listbox1 and listbox2) where the items in listbox1 will be added or removed during runtime through user input. I want the listbox2 to display its listboxitem accordingly through binding method.

For example, if listbox1 has 5 items initially, i want the listbox2 to display the same 5 items. If items in listbox1 being added or removed in runtime, I want the listbox2 to display the same data (items) as listbox1.

Can someone give me a tip? Thanks in advance.

解决方案

It's iether what jaideepsinh say and bind both of them to your original data. Or you bind listbox2 to listbox1 like so

<ListBox Name="listbox1" ItemsSource="{Binding yourdatasource}">
 </ListBox>
 <ListBox ItemsSource="{Binding ElementName=listbox1, Path=ItemSource}">
 </ListBox>


这篇关于将一个列表框listboxitem与另一个列表框绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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