c# - 使用 Material Design 时更改 ListViewItem 背景颜色

标签 c# wpf xaml material-design wpf-style

我对 WPF 相当陌生,我的应用程序设计遇到了问题。我有带有 ListView 的 UserControl,我需要动态更改 ListViewItems 的背景颜色。当我将以下代码添加到 ListView 中时,一切正常。

<ListView.Resources>
    <Style TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Status}" Value="NotStarted">
                <Setter Property="Background" Value="White" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Status}" Value="Fail">
                <Setter Property="Background" Value="#FF6666" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Status}" Value="Success">
                <Setter Property="Background" Value="#80FF80" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ListView.Resources>

问题是,当我将 Material Design 添加到 App.xaml 文件中时,颜色停止变化。

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

有什么想法可以解决这个问题吗?

最佳答案

正确答案见评论。

关于c# - 使用 Material Design 时更改 ListViewItem 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57622418/

相关文章:

c# - 控件应该被禁用和隐藏还是只是隐藏?

c# - C# 和 java 哪个更好?

c# - 使用 ItemsSource 时添加额外的项目

c# - IOException : cannot locate resource at Design time only

c# - 使用 MVVM 时如何从 ViewModel 中访问 View 成员?

c# - 有没有一种方法可以使用标准 .NET 跟踪监听器配置(而不是一个大文件)来实现滚动日志输出

c# - 将来自网络的图像保存到 Windows Phone 8.1 RT C# 中的已保存图片文件夹

c# - 如何在 WPF 中右对齐 RadioButton

c# - 在 WPF 中从一个 xaml 导航到另一个

c# - 如何将 InkToolbar 链接到 CustomControl 内的 InkCanvas?