我正在寻找一种在父网格(内容)的整个单元格中显示嵌套网格的方法。嵌套网格(menuContentControl)是使用数据模板创建的。嵌套网格中的按钮应填充单元格。我创建嵌套网格并使用以下代码设置行/列:
ContentControl menuContentControl = new ContentControl();
menuContentControl.Content = this.menuViewModel;
menuContentControl.ContentTemplate = this.MenuDataTemplateLeft;
Grid.SetRow(menuContentControl, 1);
Grid.SetColumn(menuContentControl, 1);
this.content.Children.Add(menuContentControl);
menuContentControl的数据模板:
<DataTemplate x:Name="MenuDataTemplateLeft">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Button x:Name="button_1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding MenuEntry1Description}" Grid.Row="0" Grid.Column="0"/>
<Button x:Name="button_2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding MenuEntry2Description}" Grid.Row="0" Grid.Column="1"/>
</Grid>
</DataTemplate>
将数据模板网格的水平和垂直对齐设置为&#39;拉伸&#39;不起作用。有任何想法吗?谢谢:))