Wednesday, 11 September 2013

WPF Change colour of checkmark in Listboxitem with ItemTemplate

WPF Change colour of checkmark in Listboxitem with ItemTemplate

Any WPF experts out there who can show me how to modify my styles in order
to change the the colour of the checkmark of a Checkbox contained in a
ListBoxItem. So far I have the following which is cobbled together from
MahApps styling:
<Style TargetType="ListBox" BasedOn="{StaticResource MetroListBox}"
x:Key="CheckBoxList" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding
BorderThickness}"
Background="{TemplateBinding Background}"
CornerRadius="3">
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox IsChecked="{Binding
RelativeSource={RelativeSource AncestorType={x:Type
ListBoxItem}}, Path=IsSelected}"
Content="{Binding}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource MetroListBoxItem}">
<Setter Property="MinHeight" Value="20" />
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<ContentPresenter Margin="5, 0, 0, 0"
VerticalAlignment="{TemplateBinding
VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background"
Value="{DynamicResource AccentSelectedColorBrush}"
/>
<Setter Property="Foreground"
Value="{DynamicResource TextBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource
AccentColor3}" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground"
Value="{DynamicResource GrayBrush5}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter TargetName="Border"
Property="Background" Value="{DynamicResource
GrayBrush5}" />
<Setter Property="Foreground"
Value="{DynamicResource
AccentSelectedColorBrush}" />
</MultiTrigger.Setters>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition
Property="Selector.IsSelectionActive"
Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Border" Property="Background"
Value="{DynamicResource AccentSelectedColorBrush}"
/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition
Property="Selector.IsSelectionActive"
Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter TargetName="Border"
Property="Background">
<Setter.Value>
<SolidColorBrush
Color="{DynamicResource AccentColor3}"
/>
</Setter.Value>
</Setter>
</MultiTrigger.Setters>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Regards Alan

No comments:

Post a Comment