用的ListView GridView的选择行 - 删除3D外观 [英] ListView with GridView selected row - remove 3D appearance

查看:91
本文介绍了用的ListView GridView的选择行 - 删除3D外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个GridView一个WPF的ListView。我想选定行看平的,而不是3D的风格。

I have a WPF ListView that contains a GridView. I want the selected row to look "flat" and not 3d style.

剂量人知道如何做到这一点?
谢谢,
Smadar

Dose anyone know how to do this? Thanks, Smadar

推荐答案

三维外观是默认样式的一部分。要改变这一点,你需要更换控件模板 ListViewItem的。这里是产生以下一个简单的例子:

The 3D look is part of the default style. To change this you need to replace the ControlTemplate for ListViewItem. Here's a simple example which produces the following:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListView>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="A"/>
                </GridView>
            </ListView.View>
            <ListView.Items>
                <ListViewItem Content="Item 1"/>
                <ListViewItem Content="Item 2"/>
                <ListViewItem Content="Item 3"/>
            </ListView.Items>

            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListViewItem">
                                <Border CornerRadius="2" SnapsToDevicePixels="True"
                                        BorderThickness="{TemplateBinding     BorderThickness}" 
                                        BorderBrush="{TemplateBinding BorderBrush}" 
                                        Background="{TemplateBinding Background}">
                                    <Border Name="InnerBorder" CornerRadius="1"   BorderThickness="1">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition MaxHeight="11" />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                            <Rectangle Name="UpperHighlight" Visibility="Collapsed" Fill="#75FFFFFF" />
                                            <GridViewRowPresenter Grid.RowSpan="2" 
                                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                        </Grid>
                                    </Border>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="Background" Value="LightBlue"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
    </Grid>
</Window>

请注意:默认模板这里<一款定位href=\"http://msdn.microsoft.com/en-us/library/ms788747.aspx\">http://msdn.microsoft.com/en-us/library/ms788747.aspx.既然没有办法改变的控件模板或基地之一关闭现有模板,我平时尽量保持尽可能多的默认模板的,我可以的,只有一部分改变我关心的部分。这是一个有点冗长,但应该做你要找的内容。

Note: The default templates are located here http://msdn.microsoft.com/en-us/library/ms788747.aspx. Since there is no way to change part of a ControlTemplate or base one off of an existing template, I usually try to keep as much of the default template as I can, and only change the parts I care about. It's a little verbose but should do what you're looking for.

这篇关于用的ListView GridView的选择行 - 删除3D外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆