简体   繁体   中英

Improved presentation and punctuation

I have a Grid inside a grid. I want it to to avail maximum size irrespective of window size:

  • Main_Grid should be max width
  • Grid_tool_bar should be max width

but in fact it is not and I am unable to find the reason. Here is code:

<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>

Resolved by minimizing attributes

<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>
 <Grid Name="Title_Bar" Grid.Row="0" ... Width="766" Height="31">

If you want it to autofit, do not specify a Width. Just remove that attribute.

Edit: Remove the HorizontalAlignment="Left" setters as well. At least for the outer grid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM