我有一个WPF CustomControl(比如类型" ABCControl"),它使用DataGrid
作为Control Template
。在这个模板化的数据网格RowDetailsTemplate
中,我正在显示另一个自定义控件(相同类型" 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控件,我在哪里显示另一个相同类型的控件&#34; ABCControl&#34;。 Meanig RowDetail&#39; ABCControl&#39;还将在DataGrid中显示其内容。用户使用&#39; GridSplitter&#39;调整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>