我是WPF的新手,我不了解如何在“列表”视图中更改选择颜色。我已经尝试了很多事情,但是我无法改变。以下是代码:
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"));
}
}
}
能否请您向我解释如何更改选择颜色。
编辑1:添加了ScreenShot