vendredi 19 janvier 2018

WPF ListBox Grouping With MultiSelect Checkbox

I've been working on this for days, but Can't make any headway. I've created a Listbox with Grouping using RadioButtons but I really need to use a mulitselect Checkbox, with some custom styling. Is this even possible? RadiButton has the GroupName property, but checkbox doesn't. I cant find any examples online.

Below is my currently working RadioButton ListBox. Any Help would me much appreciated.

<ListBox x:Name="comboCheckboxListBox" 
         HorizontalContentAlignment="Stretch"
         SelectedValuePath="{Binding Path=DisplayMemberPath,
                        RelativeSource={RelativeSource Mode=FindAncestor,
                                                    AncestorType={x:Type controls:RoundedComboBox}}}"
        SelectionMode="Multiple">

<ListBox.Style>
    <Style TargetType="ListBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <Border Margin="0"
                Background="Transparent"
                BorderThickness="0,1,0,0"
                Padding="0">
                        <Border.BorderBrush>
                            <SolidColorBrush Color="{StaticResource ColorComboCheckBoxItemSeparator}" />
                        </Border.BorderBrush>
                        <ItemsPresenter />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ListBox.Style>
<ListBox.Resources>
    <CollectionViewSource x:Key="CollectionVS" Source="{Binding Path=ItemsSource,
                RelativeSource={RelativeSource Mode=FindAncestor,
                                                AncestorType={x:Type controls:RoundedComboBox}}}">
        <CollectionViewSource.GroupDescriptions>
            <PropertyGroupDescription PropertyName="IS_TRACK" />
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>
</ListBox.Resources>
<ItemsControl ItemsSource="{Binding Source={StaticResource CollectionVS}}" >
    <ItemsControl.GroupStyle>
        <GroupStyle ContainerStyleSelector="{StaticResource GroupTemplateSelector}"/>
    </ItemsControl.GroupStyle>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <RadioButton Content="{Binding DESCRIPTION}" GroupName="{Binding IS_TRACK}"  />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

<Style TargetType="{x:Type GroupItem}" x:Key="ExpandTemplate">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBox">
                <Expander Header="Track">
                    <ItemsPresenter Margin="25,0,0,0"></ItemsPresenter>
                </Expander>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="{x:Type GroupItem}" x:Key="NoExpandTemplate">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <ItemsPresenter></ItemsPresenter>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

</Style>

<controls:GroupNameOrEmptyGroupItemTemplateSelector x:Key="GroupTemplateSelector"
            ExpandTemplate="{StaticResource ExpandTemplate}"
            NoExpandTemplate="{StaticResource NoExpandTemplate}"/>




Aucun commentaire:

Enregistrer un commentaire