简体   繁体   中英

Hide DataGrid row with specific Value C# WPF

I have an xml file with and they got an Attribute "Active = true". If i delete a Customer, it sets "active" to false, but the customer should still be in my xml file. I simply want to hide the DataGrid Column where the row "active" is false. So every customer with "active = false" should not be displayed in my Data Grid. I hope you understand what im trying to do: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:

<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 . You should also implement INotifyPropertyChanged to raise change notifications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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