我想要適應一個有4個單元格的wpf網格,並且屏幕上的所有時間都是全尺寸的,這樣細胞的內容就等於分開了,但是我遇到了問題......這是代碼:創建一個完整尺寸的WPF網格
<StackPanel x:Name="MainStackPanel" HorizontalAlignment="Center" Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="Rectangle">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Height" Value="Auto"/>
</Style>
</StackPanel.Resources>
<Grid x:Name="Control1" HorizontalAlignment="Center" Height="150">
<Grid.Resources>
<Style TargetType="Rectangle">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Height" Value="Auto"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle Fill="Red" Grid.Row="0" Grid.Column="1"/>
<Rectangle Fill="Blue" Grid.Row="0" Grid.Column="2"/>
<Rectangle Fill="Green" Grid.Row="1" Grid.Column="2"/>
<Rectangle Fill="Yellow" Grid.Row="1" Grid.Column="1"/>
</Grid>
</StackPanel>
請讓我知道我應該怎麼得到這個工作?還是什麼我做錯了......
是否有必要將網格包裝在StackPanel中? – Domysee
我明白你的意思了(下面評論)。基於stackpanel的setter,它並不是真的有必要。獨立網格應該以相同格式出現,除非堆疊面板還包含未列出的其他元素。 – Danielle