I am trying to change the background color of the MaterialDesign ListBoxItem style but I can't get it to work.
I know about overriding the style like this :
<Style x:Key="MaterialDesignListBoxItem"
TargetType="ListBoxItem"
BasedOn="{StaticResource MaterialDesignListBoxItem}">
</Style>
But I won't get the MaterialDesign animations as it will just be a regular button.
Is there any way to change the background color and keep the MaterialDesign look and feel?
CodePudding user response:
Set the ItemContainerStyle
property of the ListBox
to a custom Style
that is based on MaterialDesignListBoxItem
, e.g.:
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource MaterialDesignListBoxItem}">
<Setter Property="Background" Value="Green" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>