我在wpf应用程序中有大约20个按钮。现在当窗口尺寸很小时,一切都看起来不错,但每当我最大化窗口的大小时。窗口大小增加,但它们都保持在它们的位置,看起来很尴尬。
<Window x:Class="LINQ.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Linq Queries" Height="350" Width="525">
<Grid Margin="0,29,0,0">
<DataGrid x:Name="grid" AutoGenerateColumns="True" Margin="0,55,0,0"/>
<Button Content="Query1" HorizontalAlignment="Left" Margin="10,-27,0,0" VerticalAlignment="Top" Width="51" Click="Button_Click_1"/>
答案 0 :(得分:0)
要实现此目的,您需要使用Grid.RowDefinitions
和Grid.ColumnDefinitions
。示例代码:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="525"
Height="350">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Row="0"
Grid.Column="0"
Margin="5"
Content="Button 1" />
<Button Grid.Row="1"
Grid.Column="0"
Margin="5"
Content="Button 2" />
<Button Grid.Row="0"
Grid.Column="1"
Margin="5"
Content="Button 3" />
<Button Grid.Row="1"
Grid.Column="1"
Margin="5"
Content="Button 4" />
</Grid>