我有一种情况,我有多个网格中的按钮,并要求所有按钮的大小相同.我试图使用Grid.IsSharedSizeScope但是没有成功.
最终布局应如下图所示,但所有按钮的大小应相同.

XAML目前看起来像这样.有谁看到我哪里出错了?
<UserControl x:Class="UserControls.UserControl2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<GroupBox Grid.Row="0" Grid.Column="0" Header="Header 1" Grid.IsSharedSizeScope="True">
<Grid Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Button" />
<ColumnDefinition Width="Auto" SharedSizeGroup="Button" />
<ColumnDefinition Width="Auto" SharedSizeGroup="Button" />
</Grid.ColumnDefinitions>
<Button Content="A" Grid.Row="0" Grid.Column="0" Margin="2" />
<Button Content="B" Grid.Row="0" Grid.Column="1" Margin="2" />
<Button Content="C" Grid.Row="0" Grid.Column="2" Margin="2" />
</Grid>
</GroupBox>
<GroupBox Grid.Row="1" Grid.Column="0" Header="Header 2" Grid.IsSharedSizeScope="True"> …Run Code Online (Sandbox Code Playgroud) 我需要有水平和垂直标题的表(简单的PivotGrid).我在这里发现了一些类似(或几乎相同)的问题,但没有人给出解决方案.在XAML中我定义了这个结构:
<Grid x:Name="grdMain" Background="White" Grid.IsSharedSizeScope="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="1" x:Name="grdHorizontalHeader">
<!-- place for column definitions and header labels defined in code -->
</Grid>
<Grid Grid.Row="1" Grid.Column="0" x:Name="grdVerticalHeader">
<!-- place for column definitions and header labels defined in code -->
</Grid>
<Grid Grid.Row="1" Grid.Column="1" x:Name="grdContent">
<!-- place for column definitions and header labels defined in code -->
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
因此,两个头都包含一些具有一些ColumnDefinitions(resp.RowDefinitions)的网格,我需要根据Content-ColumnDefinitions调整Header-ColumnDefinitions的大小.我在代码中这样做:
foreach (var row in myColumnSource)
{ …Run Code Online (Sandbox Code Playgroud)