Wpf 自定义控件控件模板DataGrid RowDetailsTemplate绑定到同一自定义控件

Wpf 自定义控件控件模板DataGrid RowDetailsTemplate绑定到同一自定义控件,wpf,Wpf,我有一个wpfcustomcontrol(比如键入“ABCControl”),它使用DataGrid作为其控件模板。在这个模板化数据网格的行详细信息模板中,我展示了另一个自定义控件(相同类型的“ABCControl”) 在内部DataGrid的“列宽更改”后,如何重新调整父DataGrid的列宽 谢谢 “ABCControl”在Themes/Generic.xml中使用DataGrid作为模板 <Style TargetType="{x:Type local:ABCControl}

我有一个wpfcustomcontrol(比如键入“ABCControl”),它使用
DataGrid
作为其
控件模板。在这个模板化数据网格的
行详细信息模板
中,我展示了另一个自定义控件(相同类型的“ABCControl”)

在内部
DataGrid
的“列宽更改”后,如何重新调整父
DataGrid
的列宽

谢谢

“ABCControl”在Themes/Generic.xml中使用DataGrid作为模板

    <Style TargetType="{x:Type local:ABCControl}">
<ControlTemplate TargetType="{x:Type local:ABCControl}">
 <DataGrid ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Rows.Items}"
         SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem,Mode=TwoWay}">  
 <DataGrid.RowDetailsTemplate>
  <DataTemplate>
    <Border BorderThickness="0"  Padding="0"> 
    <!--Here Details is a "ABCControl" meaning it will display its conent in another datagrid-->
    <ContentControl Content="{Binding Path=Details}" FlowDirection="LeftToRight"/>
    </Border>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.Columns>
<!-- First Column--> 
<DataGridTemplateColumn Width="1*" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition  Width="Auto" />
 </Grid.ColumnDefinitions>
 <!--GridSplitter is used to resize the entire datagrid column upon dragging any column-->
   <GridSplitter Grid.Column="1" x:Name="PART_CellSplitter"  local:GridSplitterDragBehavior.IsDragSource="True"
 Tag="{Binding BindsDirectlyToSource=True,RelativeSource={RelativeSource AncestorType={x:Type DataGridCell}}}"></GridSplitter>
</Grid></DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!-- Second Column--> 
<DataGridTemplateColumn></DataGridTemplateColumn> 
</DataGrid.Columns>`
</DataGrid>

`
如何将RowHeader列绑定到一个Conent控件,其中在中显示另一个相同类型的控件“ABCControl”。Meanig RowDetail的“ABCControl”也将在DataGrid中显示其内容。用户使用“GridSplitter”调整datagrid列的大小

  • 现在有两个DataGrid(一个是top“ABCControl”,另一个是RowDetails“ABCControl”)
  • 当前的要求是,当用户重新调整外部datagrid列的大小时,内部datagrid列的大小应该以其他方式重新调整
应用程序的MainWindow.xaml将如下使用:

    <conLib:ABCControl Width="400">
            <conLib:ABCControl.Rows> 
                <ItemsControl>
                    <ItemsControl.Items>
                        <!--Row = 1 -->
                        <conLib:ABCControlItem >
                            <conLib:ABCControlItem.ItemContent> 
                                    <StackPanel Orientation="Horizontal">
                                        <CheckBox HorizontalAlignment="Center"
                                                  VerticalAlignment="Center" />
                                    </StackPanel> 
                            </conLib:ABCControlItem.ItemContent>
                            <conLib:ABCControlItem.ItemDetails>
                                <local:NewUserControl>
                                <!--NewUserControl uses a the same 'ABCControl instance inside it'-->
                                </local:NewUserControl>
                            </conLib:ABCControlItem.ItemDetails>
                        </conLib:ABCControlItem>
        </ItemsControl.Items>
</ItemsControl>
</conLib:ABCControl.Rows> 
</<conLib:ABCControl>


我觉得这个问题不太好,克莱尔。您应该放一些代码示例,让想法变得清晰。当我们开始拖动GridSplitter时,我在附加的行为中使用VisualTreeHelper GetParent和GetChild修复了它。谢谢