组合框以静态和动态数据 [英] Combobox with static and dynamic data
本文介绍了组合框以静态和动态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个绑定到一个动态资源,并具有保持在顶部有一个自定义的XAML pre指定的列表的组合框。我知道如何组合框绑定到一个动态资源,
I would like to create a combobox that binds to a dynamic resource and has a custom xaml pre-specified list that stays at the top. I know how to bind a combobox to a dynamic resource,
<ComboBox Name="comboBox1" Width="Auto" ItemsSource="{Binding}" />
我知道如何插入静态项(见 WPF - 增加静态项目组合框)。
<ComboBox Text="Is not open">
<ComboBoxItem Name="cbi1">Item1</ComboBoxItem>
<ComboBoxItem Name="cbi2">Item2</ComboBoxItem>
<ComboBoxItem Name="cbi3">Item3</ComboBoxItem>
</ComboBox>
但我不知道如何在同一时间一举两得?
but I don't know how to do both at the same time?
请注意:很显然,有很多不同的方式与自定义部件之类的要做到这一点,我只是觉得这应该是很容易莫名其妙地
Note: obviously, there are plenty of different ways to do this with custom widgets and the like, I just feel this should be quite easy somehow.
推荐答案
的 CompositeCollection 是pretty爽这一点。像这样:
CompositeCollection is pretty cool for this. Something like so:
<ComboBox>
<ComboBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={...whatever...}" />
<ComboBoxItem Name="cbi1">Item1</ComboBoxItem>
<ComboBoxItem Name="cbi2">Item2</ComboBoxItem>
<ComboBoxItem Name="cbi3">Item3</ComboBoxItem>
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
这篇关于组合框以静态和动态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文