在ListViewItem背景中创建两种颜色

时间:2016-11-12 20:42:50

标签: uwp-xaml

有没有办法让uwp中的ListViewItem背景被视为两种不同的颜色,如this control?

1 个答案:

答案 0 :(得分:1)

有两种方法可以做到这一点。

您可以设置ListView本身的背景并在那里设置颜色:

<ListView>
   <ListView.Background>
       <!-- some background, probably linear gradient brush
            with sharp stop between the two colors -->
       <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
          <GradientStop Color="DarkGray" Offset="0.2" />
          <GradientStop Color="CornflowerBlue" Offset="0.2" />
       </LinearGradientBrush>
   </ListView.Background>
</ListView>

另一种方法是分别设置每个项目的背景颜色:

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="DarkGray" Offset="0.2" />
                        <GradientStop Color="CornflowerBlue" Offset="0.2" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

enter image description here