gpt4 book ai didi

c# - 在xaml中更改listviewitem的前景色

转载 作者:行者123 更新时间:2023-11-30 18:28:13 25 4
gpt4 key购买 nike

我正在使用 C#/XAML 开发 Windows Phone 8.1 应用程序。

我有一个 ListView ,其背景设置为白色。结果,您看不到 ListView 项,因为它们的前景也是白色的。我想把它换成另一种颜色。 However, when the item is selected, I'd like to change the foreground color back to white, since when the item gets selected, the background of that item changes color (yellow), allowing white color to be seen by the user.

我已经将我的代码上传到 PasteBin:

MainPage.xaml(实际页面):http://pastebin.com/R9DG9D2J

App.xaml:http://pastebin.com/21qQxHge

在 App.xaml 中,我已经重写了 ListViewItemSelectedBackgroundThemeBrush 画笔,因此当一个项目被选中时,它有一个黄色背景而不是默认的蓝色背景。但是,我无法更改项目的前景色。 I don't want to hard-code the foreground color in the textblock within the ListViewItem's DataTemplate as if I do that, then the color won't change back to white when the item selected.

我该怎么做?

最佳答案

尝试使用 Style 触发器设置 ListViewItem 的前景色,检查 IsSelected 条件是否为真,然后在选择项目时将 Foreground 属性更改为您想要的任何颜色,这样做只有所选 ListView 项目的前景会改变

<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="ListViewItem.IsSelected" Value="True">
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>

关于c# - 在xaml中更改listviewitem的前景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25396479/

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