在数据网格WPF隐藏行根据病情

问题描述:

我需要隐藏基于参数和值在DataGrid的DataGrid行。我想通做这样的事情;

I need to hide rows in datagrid based on parameters and values in the datagrid. I figured to do something like this;

foreach (System.Data.DataRowView dr in myDataGrid.ItemsSource)
{
   //Logic to determine if Row should be hidden
   if (hideRow == "Yes")
   {
      //Hide row code
   }
}

我只是想不出如何实际隐藏的行。请注意,我不想删除该行形成的数据网格或项目源。

I just cannot figure how to actual hide the row. Please note I don't want to remove the row form the datagrid or the item source.

如果hideRow它`不表的一个字段:

If hideRow it`s not a field of table:

<DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding AnyProp, Converter={StaticResource hiddenConverter}}" Value="True">
                <Setter Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.RowStyle>

和与你的逻辑实现转换

[ValueConversion(typeof(yourPropType), typeof(bool))]
public class hiddenConverter: IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (hideRow == "Yes")
        {
           return true;
        }
        else
        {
           return false;
        }
    }


}