简体   繁体   English

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

[英]ListBox WPF: change foreground color of SelectedItem and keep Material Design?

How can i change the forground color of the SelectedItem without removing the Style from Material Design ? 如何在不从Material Design中删除样式的情况下更改SelectedItem的前景色?

This Works but will remove the Style from 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>

How can i add the Style insted of Replacing it ? 如何添加取代样式的样式?

Change Style to BasedOn="{StaticResource MaterialDesignListBoxItem}" 将样式更改为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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM