C# 将多个源绑定到单个XAML组合框中
如果我有三个不同的数据源,例如:C# 将多个源绑定到单个XAML组合框中,c#,wpf,xaml,C#,Wpf,Xaml,如果我有三个不同的数据源,例如: <CollectionViewSource x:Key="Layer"/> <CollectionViewSource x:Key="New" /> <CollectionViewSource x:Key="Option" /> 如果我想将所有结果放入一个组合框中,我将如何绑定多个源 我可以使用单个绑定: <ComboBox ItemsSource="{Binding Source={St
<CollectionViewSource x:Key="Layer"/>
<CollectionViewSource x:Key="New" />
<CollectionViewSource x:Key="Option" />
如果我想将所有结果放入一个组合框中,我将如何绑定多个源
我可以使用单个绑定:
<ComboBox ItemsSource="{Binding Source={StaticResource Layer}}" />
但是我想要这样的东西(这是行不通的):
我可以做一些类似的事情,或者我遗漏了什么或语法错误吗?您尝试过多重绑定吗?
我看到了多重绑定,它看起来就像你需要的。
这是一个例子:
<ComboBox Height="30" Width="150" Margin="5" >
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource ConditionToItemSourceConverter}">
<Binding Path="IsPerson"/>
<Binding Path="Persons"/>
<Binding Path="Employees"/>
</MultiBinding>
</ComboBox.ItemsSource>
</ComboBox>
您可以始终将代码中的3个源组合为1,并将其绑定到组合框。我认为
组合收集应该可以:
<UserControl.Resources>
<CollectionViewSource x:Key="Layer" Source="{Binding Layer}" />
<CollectionViewSource x:Key="New" Source="{Binding New}" />
<CollectionViewSource x:Key="Option" Source="{Binding Option}" />
</UserControl.Resources>
然后
<ComboBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource Layer}}" />
<CollectionContainer Collection="{Binding Source={StaticResource New}}" />
<CollectionContainer Collection="{Binding Source={StaticResource Option}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
<ComboBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource Layer}}" />
<CollectionContainer Collection="{Binding Source={StaticResource New}}" />
<CollectionContainer Collection="{Binding Source={StaticResource Option}}" />
</CompositeCollection>
</ComboBox.ItemsSource>