0

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
        }
2
  • "I have an xml file". Are you using an xmldataprovider or are you translating the data to objects? Commented Aug 19, 2020 at 15:25
  • i have textboxes, where i can input a name and a surname for example, and when i hit the save key, i write the xml file with the xmlserializer. my datagrid itemssource is my list of customers. I hope that is what you were looking for. Commented Aug 20, 2020 at 6:47

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.