简体   繁体   English

隐藏具有特定值的 DataGrid 行 C# WPF

[英]Hide DataGrid row with specific Value C# WPF

I have an xml file with and they got an Attribute "Active = true".我有一个 xml 文件,他们有一个属性“Active = true”。 If i delete a Customer, it sets "active" to false, but the customer should still be in my xml file.如果我删除一个客户,它会将“活动”设置为 false,但该客户仍应在我的 xml 文件中。 I simply want to hide the DataGrid Column where the row "active" is false.我只想隐藏“活动”行为假的 DataGrid 列。 So every customer with "active = false" should not be displayed in my Data Grid.因此,每个具有“active = false”的客户都不应该显示在我的数据网格中。 I hope you understand what im trying to do:P我希望你明白我想做什么:P

I thought about something like this:我想过这样的事情:

private void HideCustomer()
        {
            if (active == false)
            {
                DataGrid.HideRow ???? // So if the customer has this attribute set to "false" the row 
            }                         // should be hidden in the DataGrid
        }

You could define an RowStyle with a DataTrigger in the XAML markup:您可以在 XAML 标记中定义一个带有RowStyleDataTrigger

<DataGrid ...>
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsActive}" Value="False">
                    <Setter Property="Visibility" Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>

This requires that IsActive is a public property .这要求IsActive公共属性 You should also implement INotifyPropertyChanged to raise change notifications.您还应该实施INotifyPropertyChanged以引发更改通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM