zoukankan      html  css  js  c++  java
  • WPF 学习笔记(七)

    一、xaml中注释格式<!-- -->

    二、Grid 网格布局

    <Window x:Class="WpfApplication2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="50" ></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition Height="50"></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <!--设置在grid布局中的相对位置-->
            <Button Grid.Column="1" Grid.Row="1" Background="Azure"></Button>
            <!--设置在grid布局中跨越网格-->
            <Button Grid.Column="2" Grid.Row="1" Background="blue" Grid.RowSpan="2"></Button>
        </Grid>
    </Window>

    二、以代码方式实现grid布局

    namespace WpfApplication2
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                for (int i = 0; i < 10; i++)
                {
                    ColumnDefinition coldef = new ColumnDefinition();
                    gridGame.ColumnDefinitions.Add(coldef);
    
                    RowDefinition rowdef = new RowDefinition();
                    gridGame.RowDefinitions.Add(rowdef);
                }
    
                Random random = new Random();
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        //生成10×10的按钮布局
                        //Button btn = new Button();
                        //btn.Content = i + "," + j;
                        //Grid.SetRow(btn, i);
                        //Grid.SetColumn(btn, j);
                        //gridGame.Children.Add(btn);
                        //生成10×10的图片布局
                        int imgName = random.Next(1,10);
                        Image img = new Image();
                        img.Source = new BitmapImage(new Uri("Img/"+imgName+".jpg",UriKind.Relative));
                        Grid.SetRow(img, i);
                        Grid.SetColumn(img, j);
                        gridGame.Children.Add(img);
                    }
                }
            }
        }
    }
  • 相关阅读:
    k8s升级
    k8s常用命令kubeadm
    k8s部署安装-更新时间2020-10-5(docker)
    centos7安装后的优化-2019-10-12更新
    gitlab安装后出现的web IDE显示报错问题
    奋斗的路上
    Spring Boot之过滤器
    java 并发
    jar包使用
    找不到xsd文件思路
  • 原文地址:https://www.cnblogs.com/dLong/p/9536471.html
Copyright © 2011-2022 走看看