WPF XceedDataGrid use datatrigger to collapse/Hide rows

257 Views Asked by At

I am using the DataGridControl from the xceeddatagrid library(http://schemas.xceed.com/wpf/xaml/datagrid). What I am trying to do is hide/Collapse the datarow based on a property from the class model. I am trying to use a datatrigger. My issue is that the DataGrid will remove the data from the datarow but not the physical space of the row. So it leaves a blank row. I tried a regular out of the box .net datagrid and I have no issue. I stripped away all styles and still have this issue.

xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"

    <xcdg:DataGridControl  x:Name="dgr"  
               ItemsSource="{Binding Path=.Data}" 
               AutoCreateColumns="False">
        <xcdg:DataGridControl.Resources>
            <Style TargetType="{x:Type xcdg:DataRow}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=.IsTrue}" Value="true">
                        <Setter Property="Visibility" Value="Collapsed" />
                        <Setter Property="Visibility" Value="Hidden" />
                    </DataTrigger>

                </Style.Triggers>
            </Style>
        </xcdg:DataGridControl.Resources>


        <xcdg:DataGridControl.Columns>
            <xcdg:Column FieldName="IsToday" Title="Today" Width="40" />
            <xcdg:Column FieldName="Name" Title="Name" Width="70" />
            <xcdg:Column FieldName="Address" Title="Address" Width="40"  />
        </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
1

There are 1 best solutions below

0
Elininja On

Check out this doc page about the Visibility Enum. It would seem the value you need is Collapsed:

Do not display the element, and do not reserve space for it in layout.

I'm not sure that you need the "." in the Path of the DataTrigger Binding. I believe that each DataRow's IsTrue property will be accessed implicitly without the dot.

Besides that, the main issue I see is that there are two setters for the same property within the DataTrigger. Based on your description, it would seem that the DataRow's Visibility is being set to Collapsed, but then to Hidden, which does exactly what you describe as the problem:

Do not display the element, but reserve space for the element in layout.

So, I believe the solution is to remove the conflicting Visiblity Setter.