Grid grid layout in WPF

Grid grid layout in WPF

开发工具与关键技术:Visual Studio 2015、WPF
作者:黄元进
撰写时间:2019年4月24日

To use the Grid, first of all I want to add a certain number of elements RowDefinitions RowDefinitions and ColumnDefinitions and ColumnDefinitions attributes to define the number of rows and columns. Placed in the Grid panel control elements must be displayed using the Row and Column additional properties defined placed where rows and columns, where I define Grid a two rows and two columns, of a Button button in each cell Gerry surface.
Using XAML code to achieve:

<Window x:Class="Wpf动画.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStartupLocation="CenterScreen"
        Title="MainWindow" Height="350" Width="525">
    <!--定义网格,此处显示了网格线-->
    <Grid ShowGridLines="False">
        <!--自定义行-->
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <!--自定义列-->
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Button Background="DarkBlue" Foreground="LawnGreen" Content="鸣" />
        <Button Grid.Column="1" Grid.Row="1" Background="Khaki" Foreground="DarkRed" Content="の"/>
        <Button Grid.Column="2" Grid.Row="2" Background="NavajoWhite" Foreground="SkyBlue" Content="人" />
        <Button Background="ForestGreen" Foreground="Gainsboro" Grid.Column="2" Content="佐"/>
        <Button Background="Black" Content="助" Foreground="BurlyWood" Grid.Row="2"/>
    </Grid>
</Window>

Button, set the basis for a number of attributes, such as Background- background color, Foreground- font color, use Grid.Column and Grid.Row two attributes to adjust the position.
Presents the effect is as follows:
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44547949/article/details/89566145