我如何设置 GridView 中行的样式?
How do i style the rows in a GridView?
我有一个 WPF 项目,其中有一个 GridView 嵌套在一个 ListView 中,我想更改行的样式。
我想更改光标在上方时的颜色。
我该怎么做?
这是我的XAML
<ListView x:Name="list_User_Events" Background="{StaticResource BorderDarkGreen}" Foreground="White" BorderThickness="0" BorderBrush="{x:Null}" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Name" DisplayMemberBinding="{Binding Name}"></GridViewColumn>
<GridViewColumn Width="50" Header="Interval" DisplayMemberBinding="{Binding Interval}"></GridViewColumn>
<GridViewColumn Width="160" Header="Type" DisplayMemberBinding="{Binding EventType}"></GridViewColumn>
<GridViewColumn Header="Command" DisplayMemberBinding="{Binding Command}"></GridViewColumn>
<GridViewColumn Header="Action">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="btn_list_user_Event_Delete" Click="btn_list_user_Event_Delete_Click">Delete</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
您需要将 ListView 上的 ItemContainerStyle 设置为 TargetType 为 ListViewItem 的样式:
<ListView
x:Name="list_User_Events"
Background="{StaticResource BorderDarkGreen}"
Foreground="White"
BorderThickness="0"
BorderBrush="{x:Null}"
SelectionMode="Single"
>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<!-- Setters, Triggers, etc. -->
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<!-- etc. etc. snip snip -->
</ListView.View>
</ListView>
如果您想为多个相似的列表视图重用该样式,您可以在 Window.Resources 或 UserControl.Resources 中使用 x:Key
属性定义它并将其用作静态资源:
<ListView
ItemContainerStyle="{StaticResource ListViewGridViewItemStyle}"
我有一个 WPF 项目,其中有一个 GridView 嵌套在一个 ListView 中,我想更改行的样式。
我想更改光标在上方时的颜色。
我该怎么做?
这是我的XAML
<ListView x:Name="list_User_Events" Background="{StaticResource BorderDarkGreen}" Foreground="White" BorderThickness="0" BorderBrush="{x:Null}" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Name" DisplayMemberBinding="{Binding Name}"></GridViewColumn>
<GridViewColumn Width="50" Header="Interval" DisplayMemberBinding="{Binding Interval}"></GridViewColumn>
<GridViewColumn Width="160" Header="Type" DisplayMemberBinding="{Binding EventType}"></GridViewColumn>
<GridViewColumn Header="Command" DisplayMemberBinding="{Binding Command}"></GridViewColumn>
<GridViewColumn Header="Action">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="btn_list_user_Event_Delete" Click="btn_list_user_Event_Delete_Click">Delete</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
您需要将 ListView 上的 ItemContainerStyle 设置为 TargetType 为 ListViewItem 的样式:
<ListView
x:Name="list_User_Events"
Background="{StaticResource BorderDarkGreen}"
Foreground="White"
BorderThickness="0"
BorderBrush="{x:Null}"
SelectionMode="Single"
>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<!-- Setters, Triggers, etc. -->
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<!-- etc. etc. snip snip -->
</ListView.View>
</ListView>
如果您想为多个相似的列表视图重用该样式,您可以在 Window.Resources 或 UserControl.Resources 中使用 x:Key
属性定义它并将其用作静态资源:
<ListView
ItemContainerStyle="{StaticResource ListViewGridViewItemStyle}"