Search code examples
c#wpfmvvmcomboboxwpftoolkit

How to bind a collection to Extended WPF Toolkit's DropdownButton?


I'm trying to create a SIMPLE dropdownlist/combobox with a title/header. I repeat SIMPLE. I found this pretty DropdownButton in Extended WPF Toolkit here. The problem is.. It does not contain anything like ItemsSource or DataSource, so I can't even bind my collection = I can't use MVVM pattern (which doesn't make sense in WPF). Am I missing something here?

Here's the example of my "goal" using ComboBox

            <ComboBox Margin="5" ItemsSource="{Binding MyOptions}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding DisplayName}" IsChecked="{Binding IsChecked, Mode=TwoWay}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

This example is almost perfect, but I can't specify a header in ComboBox with simple Header="Check your options:".

The question is: How can I bind a collection from ViewModel to DropdownButton control?

Thanks,


Solution

  • The solution could be:

                <wpfTool:DropDownButton Content="Options">
                    <wpfTool:DropDownButton.DropDownContent>
                        <ListView Margin="0" ItemsSource="{Binding MyOptions}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <CheckBox Content="{Binding DisplayName}" IsChecked="{Binding IsChecked, Mode=TwoWay}" />
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </wpfTool:DropDownButton.DropDownContent>
                </wpfTool:DropDownButton>