绑定和Itemscontrol到多个源? [英] Bind and Itemscontrol to more than one source?

查看:112
本文介绍了绑定和Itemscontrol到多个源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上,我有一个ItemsControl绑定到UI元素的集合,并在画布中显示该集合.我想知道是否可以将ItemsControl的ItemsSource绑定到多个源?因为我要在同一画布上显示UI元素的另一个集合,但我不知道该怎么做.如果不可能,那么有人可以建议解决方法吗?谢谢!

So basically I have an ItemsControl that is bound to a collection of UI elements and displays that collection in a canvas. I was wondering if it''s possible to bind the ItemsSource of an ItemsControl to more than one source? Because I have another collection of UI elements that I want to display in that same canvas but I don''t know how to do that. If it''s not possible can anyone suggest a workaround? Thanks!

推荐答案

创建一个新的集合,将其他两个项目复制并绑定到该项目吗?
Create a new collection that copies the items from both the others and bind to that?


DataContext可以可以在视觉树的任何位置进行设置,因此您可以直接在需要使用的位置进行设置.这意味着您不必担心,因为您的第二个UI元素可以绑定到另一个DataContext.
The DataContext can be set anywhere up the visual tree, so you can set it directly at the point that needs to be used. This means that you don''t need to worry about this, because your second UI elements can bind to a different DataContext instead.


您好,

我认为这是您正在寻找的示例:
Hello,

I think this is the example you are looking for :
<ListBox Name="listbox" DisplayMemberPath="Test">
       <ListBox.ItemsSource>
           <CompositeCollection>
               <CollectionContainer Collection="{Binding Source={StaticResource myDataSource2}, Path=One}"/>
               <CollectionContainer Collection="{Binding Source={StaticResource myDataSource}, Path=Two}"/>
               <CollectionContainer Collection="{Binding Source={StaticResource myDataSource}, Path=Three}"/>
           </CompositeCollection>
       </ListBox.ItemsSource>
   </ListBox>




希望对您有帮助!




Hope this help you !


这篇关于绑定和Itemscontrol到多个源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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