ListBox WPF:更改 SelectedItem 的前景色并保留 Material Design?

Ger*_*erd 2 c# wpf listbox listboxitem material-design

如何在不从 Material Design 中删除样式的情况下更改 SelectedItem 的前景色?

这有效,但会从 Material Design 中删除样式:

<ListBox TextElement.Foreground="Black">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel IsItemsHost="True" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True" >
                            <Setter Property="FontWeight" Value="Bold" />
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="Foreground" Value="White" />
                        </Trigger>
                    </Style.Triggers>
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                    </Style.Resources>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>
Run Code Online (Sandbox Code Playgroud)

我如何添加替换它的样式?

Sve*_*dos 5

将样式更改为 BasedOn="{StaticResource MaterialDesignListBoxItem}"

 <ListBox.ItemContainerStyle>
       <Style TargetType="ListBoxItem" BasedOn="{StaticResource MaterialDesignListBoxItem}">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True" >
                            <Setter Property="FontWeight" Value="Bold" />
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="Foreground" Value="White" />                               
                        </Trigger>
                    </Style.Triggers>
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                    </Style.Resources>
      </Style>
 </ListBox.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)