1

我在网格中有一个网格。无论窗口大小如何,我都希望它能够利用最大大小:

  • Main_Grid 应该是最大宽度
  • Grid_tool_bar 应该是最大宽度

但实际上并非如此,我无法找到原因。这是代码:

<Window x:Class="SocialNetworkingApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Background="White" WindowStyle="None" HorizontalAlignment="Stretch" WindowState="Normal" AllowsTransparency="True" WindowStartupLocation="CenterScreen">
    <Border Margin="0,0,0,0" BorderBrush="Black" BorderThickness="1,1,1,1" >
        <Grid x:Name="Main_Grid" Background="White" Width="Auto" Height="Auto" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="25"/>
                <RowDefinition Height="50"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="20"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
            <Grid Name="Title_Bar" Grid.Row="0" VerticalAlignment="Top" ShowGridLines="True" Grid.IsSharedSizeScope="True" MouseDown="Drag_Window" Background="#FF4FA2DA" HorizontalAlignment="Left" Width="766" Height="31">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="120" />
                </Grid.ColumnDefinitions>
            </Grid>
        </Grid>
    </Border>
</Window>

通过最小化属性来解决

<Window x:Class="SocialNetworkingApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Background="White" WindowStyle="None"  WindowState="Normal" AllowsTransparency="True" WindowStartupLocation="CenterScreen">
    <Border Margin="0,0,0,0" BorderBrush="Black" BorderThickness="1,1,1,1" >
        <Grid x:Name="Main_Grid" Background="White" >
            <Grid.RowDefinitions>
                <RowDefinition Height="10" />
                <RowDefinition Height="20"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="20"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
            <Grid Name="Title_Bar" Grid.Row="0" Height="Auto" Background="#FF4FA2DA" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="120" />
                </Grid.ColumnDefinitions>
            </Grid>
        </Grid>
    </Border>
</Window>
4

1 回答 1

0
 <Grid Name="Title_Bar" Grid.Row="0" ... Width="766" Height="31">

如果您希望它自动调整,请不要指定宽度。只需删除该属性。

编辑:也删除HorizontalAlignment="Left"设置器。至少对于外部网格。

于 2012-10-19T22:58:24.630 回答