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

Hide DataGrid row with specific Value C# WPF

我有一个 xml 文件,他们有一个属性“Active = true”。如果我删除一个客户,它会将“活动”设置为 false,但该客户仍应在我的 xml 文件中。我只想隐藏“活动”行为假的 DataGrid 列。因此,每个具有“active = false”的客户都不应该显示在我的数据网格中。我希望你明白我想做什么 :P

我想到了这样的事情:

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
        }

您可以在 XAML 标记中定义带有 DataTriggerRowStyle

<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>

这要求 IsActivepublic 属性。您还应该实施 INotifyPropertyChanged 以引发更改通知。