Combobox with static and dynamic data

binding, combobox, wpf

Solution

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>

Problem

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}" /> ``` and I know how to insert static items (see WPF - add static items to a combo box ). ``` <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.

Original source

Related problems