ListView中的第一项自定义样式边框 [英] First item custom style border in ListView

查看:32
本文介绍了ListView中的第一项自定义样式边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为 ListView 中的第一项设置不同的样式?就我而言,我想更改第一个项目边框,以获得这样的 GUI:

How can I set different style for first item in ListView? In my case, I want to change first item border, to get GUI like this:

我当前的代码(没有顶部边框):

My current code (no top border):

<ListView 
    ItemsSource="{Binding MyData}">
    <ListView.ItemContainerStyle>
        <Setter Property="BorderThickness" Value="0,0,0,1" />
    </ListView.ItemContainerStyle>
</ListView>

推荐答案

有一个非常简单的解决方案.您不必编写自定义转换器等.使用 PreviousData in RelativeSource

There is a very simple solution. You don't have to write custom converters etc. Use PreviousData in RelativeSource

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="BorderThickness" Value="0,0,0,1" />
        <Style.Triggers>
            <DataTrigger 
                Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                <Setter Property="BorderThickness" Value="0,1,0,1"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>

这篇关于ListView中的第一项自定义样式边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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