gpt4 book ai didi

c# - 列表框 WPF : change foreground color of SelectedItem and keep Material Design?

转载 作者:行者123 更新时间:2023-12-02 03:32:37 25 4
gpt4 key购买 nike

如何在不从 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>

如何添加替换样式?

最佳答案

将样式更改为 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>

关于c# - 列表框 WPF : change foreground color of SelectedItem and keep Material Design?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51386190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com