none
设置了LISTVIEWITEM样式后为什么是渐变的而不是纯色 RRS feed

  • 问题

  •         <Style TargetType="{x:Type ListViewItem}">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="#01B4A1"/>
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="Height" Value="40"/>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="False">
                        <Setter Property="Height" Value="40"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

    图片地址H TTP:// social.microsoft.com/Forums/getfile/1087818

    2017年6月20日 3:09

答案

  • Hi,

    你可以尝试使用模板来设置:

     <ListView>
                <ListView.Resources>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListViewItem}">
                                    <Border x:Name="Bd" BorderBrush="Gray" CornerRadius="5"  BorderThickness="0,0,0,2" Margin="2" Padding="5" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="#01B4A1"/>
                                <Setter Property="Foreground" Value="Red"/>
                                <Setter Property="BorderBrush" Value="Green" />
                                <Setter Property="Height" Value="40"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="False">
                                <Setter Property="Background" Value="Beige"/>
                                <Setter Property="Height" Value="40"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListView.Resources>
                <ListViewItem FontSize="20">aaaa</ListViewItem>
                <ListViewItem FontSize="20">bbbb</ListViewItem>
                <ListViewItem FontSize="20">cccc</ListViewItem>
                <ListViewItem FontSize="20">dddd</ListViewItem>
            </ListView>

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2017年6月20日 5:55
    版主