单个DataGrid行可见性 [英] Individual DataGrid Row Visibility

查看:106
本文介绍了单个DataGrid行可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF DataGrid 绑定到父EF对象内的 Entity Framework 对象的集合。以下行:

I have a WPF DataGrid bound to a collection of Entity Framework objects that's inside a parent EF object. Something along the lines of:

<DataGrid ItemsSource="{Binding SelectedCustomer.Orders}" />

现在,当我想删除一个订单时,我不想实际删除它数据源,我只想将其 IsDeleted 属性设置为true,以便保留数据。

Now when I want to "delete" an Order, I don't want to actually delete it from the data source, I simply want to set its IsDeleted property to true so the data is retained.

我的问题是:如果它是 IsDeleted 属性是真的,我如何获取我的 DataGrid 跳过一行?我真的想使用绑定而不是codebehind。这样的事情会很棒:

My question is: how can I get my DataGrid to skip a row if it's IsDeleted property is true? I would really like to use binding and not codebehind. Something like this would be wonderful:

<DataGrid ItemsSource="{Binding SelectedCustomer.Orders}" RowVisibilityPath="IsDeleted" />

沿着 DisplayMemberPath 的行的种类。我意识到我需要转换 IsDeleted 的状态,但这是一个不同的主题。

Kind of along the lines of DisplayMemberPath. I realize I would need to convert the state of IsDeleted, but that's a different topic.

任何想法? / p>

Any ideas?

推荐答案

除了使用所提到的CollectionView,您可以通过RowStyle:

Aside from using a CollectionView as mentioned you can do this via the RowStyle:

<DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsDeleted}" Value="True">
                <Setter Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.RowStyle>

这篇关于单个DataGrid行可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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