Search code examples
c#wpfxamlmaterial-designwpf-style

Changing ListViewItem background colour while using Material Design


I'm fairly new to WPF and I've run into a problem with my app design. I have UserControl with ListView and I need to change background colour of ListViewItems dynamically. When I add the following code into my ListView everything works fine.

<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>

The problem is that when I add Material Design into my App.xaml file, the colours stop to change.

<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>

Any ideas how to solve this?


Solution

  • Correct answer in the comments.