简体   繁体   English

如何在GridView中设置行的样式?

[英]How do i style the rows in a GridView?

I have a WPF project where i have a GridView nested inside a ListView and i want to change the style for the rows. 我有一个WPF项目,其中有一个嵌套在ListView中的GridView,我想更改行的样式。

I want to change the color for when the cursor is above. 我想更改光标上方的颜色。

How do i do that? 我怎么做?

Here is my XAML 这是我的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>

You'll need to set the ItemContainerStyle on the ListView to a Style with a TargetType of ListViewItem: 您需要将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>

If you want to reuse the style for multiple similar listviews, you would define it in Window.Resources or UserControl.Resources with an x:Key attribute and use it as a static resource: 如果要在多个相似的列表视图中重用该样式,则可以在Window.Resources或UserControl.Resources中使用x:Key属性对其进行定义,并将其用作静态资源:

<ListView
    ItemContainerStyle="{StaticResource ListViewGridViewItemStyle}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM