将网格宽度设置为自动

我的 ATM WPF 应用程序有这个界面。我使用了停靠面板和网格。它看起来不错,但如果我最大化它,它就不会“响应”。我尝试将网格宽度更改为 * 但它不起作用。如果我设置为“自动”,看起来不太好。


<Window x:Class="WpfApp1.MainWindow"

    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"

    xmlns:local="clr-namespace:WpfApp1"

    mc:Ignorable="d"

    Title="MainWindow" Height="600" Width="600">


    <DockPanel>

    <Button DockPanel.Dock="Left" VerticalContentAlignment="Top">

        <StackPanel >

            <Button Content="Left Button 1" Height="100"></Button>

            <Button Content="Left Button 2" Height="100"></Button>

            <Button Content="Left Button 3" Height="100"></Button>

        </StackPanel>

    </Button>

    <Button DockPanel.Dock="Right"  VerticalContentAlignment="Top">

        <StackPanel>

            <Button Content="Right Button 1" Height="100"></Button>

            <Button Content="Right Button 2" Height="100"></Button>

            <Button Content="Right Button 3" Height="100"></Button>

        </StackPanel>

    </Button>

    <Button DockPanel.Dock="Bottom" VerticalContentAlignment="Bottom" >

        <Grid Margin="10" Width="400">

            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="*"/>

                <ColumnDefinition Width="*"/>

                <ColumnDefinition Width="*"/>

            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>

                <RowDefinition Height="*"/>

                <RowDefinition Height="*"/>

                <RowDefinition Height="*"/>

                <RowDefinition Height="*"/>

                <RowDefinition Height="*"/>

            </Grid.RowDefinitions>

        </Grid>

    </Button>

</DockPanel>

顺便问一下,我可以只使用网格来处理这里的所有内容,还是必须使用停靠面板和网格的组合?

https://img2.mukewang.com/64e1c12e00012a6905910596.jpg

开满天机
浏览 71回答 1
1回答

aluckdog

您可以使用一组嵌套网格:<Grid>&nbsp; &nbsp; <Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="100"/>&nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition/>&nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="100" />&nbsp; &nbsp; </Grid.ColumnDefinitions>&nbsp; &nbsp; <StackPanel Grid.Column="0">&nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Left Button 1" Height="100"/>&nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Left Button 2" Height="100"/>&nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Left Button 3" Height="100"/>&nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; <StackPanel Grid.Column="2">&nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Right Button 1" Height="100"/>&nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Right Button 2" Height="100"/>&nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Right Button 3" Height="100"/>&nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; <Grid Grid.Column="1">&nbsp; &nbsp; &nbsp; &nbsp; <Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition/>&nbsp; &nbsp; &nbsp; &nbsp; </Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; <Grid Grid.Row="0" Margin="10">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Grid.Column="0" VerticalAlignment="Center" Text="PIN"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBox Grid.Column="1" VerticalAlignment="Center"/>&nbsp; &nbsp; &nbsp; &nbsp; </Grid>&nbsp; &nbsp; &nbsp; &nbsp; <Grid Grid.Row="1" Margin="10">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!-- the number keypad -->&nbsp; &nbsp; &nbsp; &nbsp; </Grid>&nbsp; &nbsp; </Grid></Grid>
打开App,查看更多内容
随时随地看视频慕课网APP