I'm new in WPF and xamlDataGrid. I try to hide cell using trigger. Cell visibility is based on value of other bounded object's property (IsChecked)It works but there is empty space where collapsed column was placed.If I don't use trigger in style and simply collapce cell without condition (see commented xaml code) then there is no empty space.
How to collapse cell using trigger without remaining empty space?
Off: How to format xml-code in this forum?
<
igDP:XamDataGrid Margin="12,37,12,12" Name="xamDataGrid1">
<igDP:XamDataGrid.Resources>
<Style x:Key="HiddenCell" TargetType="{x:Type igDP:CellPresenter}">
<!--<Setter Property="Visibility" Value="Collapsed"/>-->
<Style.Triggers>
<DataTrigger Binding="{Binding Path=DataItem.IsChecked}" Value="false">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoArrangeCells="Never" AutoGenerateFields="False" LabelLocation="InCells"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.FieldSettings>
<igDP:FieldSettings CellContentAlignment="LabelLeftOfValueAlignBottom"/>
</igDP:FieldLayout.FieldSettings>
<igDP:FieldLayout.Fields>
<igDP:Field Name="FirstName" Label="First Name"/>
<igDP:Field Name="LastName" Label="Last Name" Column="1"/>
<igDP:Field Name="RecordDate" Label="Record date" Row="1">
<igDP:Field.Settings>
<igDP:FieldSettings CellPresenterStyle="{StaticResource HiddenCell}"/>
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="IsChecked" Label="Checked" Row="2"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Hello,
I was not able to reproduce this. Can you please give us the code you are using to hide the CellPresenter in procedura code?
What you mean "hide the CellPresenter in procedura code"? I'm trying to hide cell using trigger defined in xaml.
I attached zip-file that contains folder with solution and screenshot of window with grid.
Any resolution to this issue? I am also looking for the solution. Thanks for presenting such a nice sample.
Does it mean that it is impossible to hide cells using trigger?
Alexey,
I missed the commented setter in the xaml and assumed that you are using procedural code to hide the CellPresenter. I think that this happens, because with the setter, the visibility is set to collapsed before the cells/labels are arranged. However, with a trigger, they are hidden after that. This means that the rest of the labels already have Row/Column properties set and that prevents them from collapsing this space.