I am new to WPF and i am not getting how to change the selection color in the List view. I have tried many things but i am not able to change. Following is the code:
MainWindow.xaml:
<Window x:Class="MyListView.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MyListView"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
</Style.Resources>
</Style>
</Window.Resources>
<Grid>
<ListView x:Name="MovieListView" Margin="30,0,50,48" Height="344" VerticalAlignment="Bottom">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path= MovieID}" />
<TextBlock Text="{Binding Path= MovieName}" FontWeight="Bold" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
MainWindow.xaml.cs
namespace MyListView
{
public class MyDataModel
{
public String MovieName { get; set; }
public String MovieID { get; set; }
public MyDataModel(String ID, String Name)
{
MovieID = ID;
MovieName = Name;
}
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MovieListView.Items.Add(new MyDataModel("MV_1","Movie 1" ));
MovieListView.Items.Add(new MyDataModel("MV_2", "Movie 2"));
MovieListView.Items.Add(new MyDataModel("MV_3", "Movie 3"));
}
}
}
Can you please explain to me how to change the selection color.
Edit1 : Added ScreenShot