我有這兩個網格:
<Grid Margin="2.0cm, 2.0cm, 1.5cm, 0.5cm" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<DockPanel VerticalAlignment="Stretch" Grid.Row="1" Background="Red">
<Grid Height="100" DockPanel.Dock="Top" Background="Blue"/>
<Grid Height="100" DockPanel.Dock="Bottom" Background="Yellow"/>
</DockPanel>
</Grid>
結果是這樣的:

我希望藍色網格填充所有空間,直到黃色網格和黃色網格應該填充所有空間直到底部。所以我不想看到紅色。
另外,我希望如果黃色網格折疊,藍色網格應該填滿所有空間。
我必須設定垂直對齊來拉伸,但我沒有得到想要的行為,在這種情況下我不會看到網格。
我怎樣才能得到我想要的行為?
非常感謝。
解決方案
我可以用這段代碼解決這個問題:
<Grid Margin="2.0cm, 2.0cm, 1.5cm, 0.5cm" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="AUTO"/>
</Grid.RowDefinitions>
<Grid DockPanel.Dock="Top" Background="Yellow" Visibility="Visible" VerticalAlignment="Stretch" Grid.Row="0"/>
<Grid DockPanel.Dock="Bottom" Background="Blue" Visibility="Visible" Height="100" VerticalAlignment="Bottom" Grid.Row="1"/>
</Grid>
uj5u.com熱心網友回復:
如果您希望您的網格平均共享空間,我認為您應該使用 UniformGrid。如果黃色網格折疊,藍色網格將填滿整個空間。
<Grid Margin="2.0cm, 2.0cm, 1.5cm, 0.5cm" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<UniformGrid Background="Red" Columns="1">
<Grid Background="Blue"/>
<Grid Background="Yellow"/>
</UniformGrid>
</Grid>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/315350.html
標籤:小白
上一篇:WPFlistView獲取檢查項
