0

i need to collapse the current DataGridRow based on a cell's DataContext value ,

   <DataGridTemplateColumn>
       <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                   <ContentControl Content="{Binding}"/>

                    <DataTemplate.Triggers>                            
                         <DataTrigger Binding="{Binding IsParentExpanded}" Value="False">
                                <!-- Here i wan't to Collapse the DataGridRow-->
                         </DataTrigger>                            
                     </DataTemplate.Triggers>

                </DataTemplate>                        
          </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>

any ideas how this can be done ?

just to clarify i wan't there to be a Setter where the Target in the RelativeSource of type DataGridRow.

currently i apply this change threw :

   <DataGrid.RowStyle>
        <Style TargetType="{x:Type DataGridRow}">
             <Style.Triggers>
                 <DataTrigger Binding="{Binding IsParentExpanded}" Value="False">
                      <Setter Property="Visibility" Value="Collapsed"/>
                  </DataTrigger>
             </Style.Triggers>                    
         </Style>
    </DataGrid.RowStyle>

i was wondering if there's a different way , only using xaml of course , since i can traverse up the visual tree and do that in code.

eran otzap
  • 12,293
  • 20
  • 84
  • 139

1 Answers1

0

You should do this in RowStyle like below

    <DataGrid>
        <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsParentExpanded}" Value="False">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                </Style.Triggers>
             </Style>
        </DataGrid.RowStyle>
    </DataGrid>
Nitin
  • 18,344
  • 2
  • 36
  • 53