C# WPF Static item and binding combobox

320 Views Asked by At

I am trying to do some simple thing in WPF but can't find the way to do it.

I have a ComboBox in a DataGrid header to filter data. The data is binded to a GrouBy statement of all my data.

These show some CheckBox The XAML code is:

<DataGridTextColumn x:Name="Type"
                    Binding="{Binding TypeOfData, Mode=OneTime}"
                    SortMemberPath="TypeOfData"
                    IsReadOnly="true"
                    CanUserSort="true">
    <DataGridTextColumn.Header>
        <DockPanel>
            <Label Content="Type Of Data"
                   DockPanel.Dock="Left"/>  
            <ComboBox x:Name="comboBoxType"
                      DockPanel.Dock="Right" 
                      SelectionChanged="comboBoxType_SelectionChanged">                         
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel x:Name="itemsComboBox">
                           <CheckBox Name="checkBoxType"
                                     IsChecked="False"
                                     Content="{Binding Key}"
                                     Unchecked="FilterChange" 
                                     Checked="FilterChange"/>
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </DockPanel>
    </DataGridTextColumn.Header>
</DataGridTextColumn>

The code behind fore binding is:

comboBoxType.ItemsSource = allData.GroupBy(data=> data.TypeOfData).OrderBy(grp=> grp.Key);

And this work.

But now I want to add 2 button to check and uncheck all at the end or at the start of the ComboBox but I can't seem to find how to add those static button in a dynamic data template.

Edit Answer to grek40: I want the buttons in the combobox Items before or after the checkboxes.

CompositeCollection could help but I can't seem to make it work.

Thank You

1

There are 1 best solutions below

0
mm8 On

Replace the DockPanel with a Grid that has several ColumnDefinitions:

<DataGridTextColumn x:Name="Type" Binding="{Binding TypeOfData, Mode=OneTime}" SortMemberPath="TypeOfData" IsReadOnly="true" CanUserSort="true">
    <DataGridTextColumn.Header>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Label Content="Type Of Data"  />
            <ComboBox x:Name="comboBoxType"
                      Grid.Column="1"
                      SelectionChanged="comboBoxType_SelectionChanged">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel x:Name="itemsComboBox">
                            <CheckBox Name="checkBoxType"
                                      IsChecked="False"
                                      Content="{Binding Key}"
                                      Unchecked="FilterChange" 
                                      Checked="FilterChange"/>
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Button Content="Check"
                    Grid.Column="2" />
        </Grid>
    </DataGridTextColumn.Header>
</DataGridTextColumn>