Wpf DataTemplate目标父元素中的Setter(影响CellTemplate中的DataGridRow)

Wpf DataTemplate目标父元素中的Setter(影响CellTemplate中的DataGridRow),wpf,datagrid,datatrigger,celltemplate,Wpf,Datagrid,Datatrigger,Celltemplate,我需要根据单元格的DataContext值折叠当前DataGridRow <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ContentControl Content="{Binding}"/> <DataT

我需要根据单元格的DataContext值折叠当前DataGridRow

   <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>

你知道怎么做吗

我只是想澄清一下,在DataGridRow类型的RelativeSource中,我不希望有一个Setter来定义目标

目前我应用此更改:

   <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>


我想知道是否有另一种方法,当然只使用xaml,因为我可以遍历可视化树并在代码中这样做

您应该在
行样式中执行此操作,如下所示

    <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>

我正在那里做。我想在牢房里做。无论如何,谢谢你,我应该提到这一点。