2

GridView を含む WPF ListView があります。選択した行を 3D スタイルではなく「フラット」に見せたい。

誰かがこれを行う方法を知っていますか?ありがとう、スマダー

4

1 に答える 1

9

3Dルックはデフォルトスタイルの一部です。これを変更するには、ControlTemplateforを置き換える必要がありますListViewItem。これは、以下を生成する簡単な例です。ListViewのスクリーンショット

<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>

注:デフォルトのテンプレートは、http://msdn.microsoft.com/en-us/library/ms788747.aspxにあります。既存のテンプレートの一部またはベースの一部を変更する方法がないためControlTemplate、通常、デフォルトのテンプレートをできるだけ多く保持し、気になる部分のみを変更するようにしています。少し冗長ですが、探していることを実行する必要があります。

于 2012-12-30T22:54:42.663 に答える