当前位置: 首页 > article >正文

71.StackPanel黑白棋盘 WPF例子 C#例子

 就是生成黑白棋盘,利用该控件能自动排列的功能。用一个横向的StackPanel嵌套纵向的StackPanel,然后在里面添加设定好长和高的矩形。

因为StackPanel是按照控件的大小展示的。所以如果不设置长和宽。就会显示不出矩形。

 <StackPanel Orientation="Horizontal" Margin="0">
                <StackPanel Orientation="Vertical" Margin="0">

横向与纵向要设置,才能排列

展示:

<Window x:Class="StackPanel.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:StackPanel"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Border BorderThickness="40" BorderBrush="Brown">
            <StackPanel Orientation="Horizontal" Margin="0">
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Margin="0">
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                    <Rectangle Fill="White" Width="50" Height="50"/>
                    <Rectangle Fill="Black" Width="50" Height="50"/>
                </StackPanel>

            </StackPanel>
        </Border>
        
        
    </Grid>

</Window>


http://www.kler.cn/a/535214.html

相关文章:

  • 前端控制器模式
  • mybatis plus 持久化使用技巧及场景
  • Centos 8 离线升级openssh 9.9
  • 一个RPC框架应该解决哪些问题?
  • python3中错误与异常初识
  • 大型三甲医院算力网络架构的深度剖析与关键技术探索
  • 基于Redis分布式锁
  • 达梦数据库从单主模式转换为主备模式
  • (苍穹外卖)项目结构
  • 深度学习|表示学习|卷积神经网络|DeconvNet是什么?|18
  • Android studio 编译速度增加
  • 微服务中服务治理都包含什么
  • 【回溯+剪枝】单词搜索,你能用递归解决吗?
  • [原创](Modern C++)现代C++的关键性概念: 文件编码细节之一:BOM(Byte Order Mark, 字节顺序标记)
  • 分库分表详解
  • 02.06 网络编程_概述
  • 补小识JVM中的分代收集理论
  • 离线安装Appium Server
  • 结合R语言、ArcGIS Pro、ChatGPT+生态学模型(PLUS模型、InVEST模型)的生态系统服务的多情景模拟预测及其应用
  • K8S组件架构
  • Eureka 高频考点
  • 网络工程师 (22)网络协议
  • C# foreach循环:性能提升
  • JAVA异步的UDP 通讯-服务端
  • WGCLOUD监控系统部署教程
  • WPS计算机二级•幻灯片的输出、打印与分享