Individual data row visibility

I have a WPF DataGrid associated with a set of Entity Framework objects that reside inside the parent EF object. Sort of:

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

Now that I want to β€œdelete” the order, I don’t want to actually delete it from the data source, I just want to set its IsDeleted property to true so that the data is saved.

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

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

View along the lines of DisplayMemberPath . I understand that I will need to convert the state to IsDeleted , but this is a different topic.

Any ideas?

+6
source share
3 answers

Besides using CollectionView, as already mentioned, you can do this via 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> 
+21
source
 <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <Setter Property="Visibility" Value="{Binding IsDeleted, Converter={StaticResource BoolToVisibility}}"/> </Style> </DataGrid.RowStyle> 
+4
source

You can use CollectionView to filter your data.

+2
source

Source: https://habr.com/ru/post/887559/


All Articles