0

我在 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"/>
4

1 回答 1

0

为此,您需要使用Grid.RowDefinitionsGrid.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>

于 2013-05-29T07:04:33.777 回答