【发布时间】:2018-07-05 21:17:34
【问题描述】:
我正在创建一个表单,它将并排显示到控件,如下例所示。 问题是当我将一个控件的可见性设置为“折叠”时,另一个控件并没有填满所有窗口。
<Window x:Class="Example"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Height="600" Width="600">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button>Button 1</Button>
<Button Grid.Column="1" Visibility="Visible">Button 2</Button>
</Grid>
</Window>
当我将按钮 2 的可见性设置为折叠时,如何使“按钮 1”填充所有窗口?
两者都可见时的当前效果:
+---------------------+
| | |
| | |
| | |
| Button 1 | Button 2 |
| | |
| | |
| | |
+---------------------+
Button2折叠时:
+---------------------+
| | |
| | |
| | |
| Button 1 | |
| | |
| | |
| | |
+---------------------+
期望:
+---------------------+
| |
| |
| |
| Button 1 |
| |
| |
| |
+---------------------+
【问题讨论】:
-
您是否尝试过使用自动列宽
-
对 2 列使用
Width="*"意味着它们将总是都获得 50%。 -
@GWigWam,还有其他方法吗?
-
使用不同的面板,例如一个统一网格。