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

news/2025/2/8 21:49:44/

 就是生成黑白棋盘,利用该控件能自动排列的功能。用一个横向的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.ppmy.cn/news/1570422.html

相关文章

力扣1022. 从根到叶的二进制数之和(二叉树的遍历思想解决)

Problem: 1022. 从根到叶的二进制数之和 文章目录 题目描述思路复杂度Code 题目描述 思路 遍历思想(利用二叉树的先序遍历) 1.在先序遍历的过程中&#xff0c;用一个变量path记录并更新其经过的路径上的值&#xff0c;当遇到根节点时再将其加到结果值res上&#xff1b; 2.该题…

pycharm配置anaconda环境时找不到python.exe解决办法

方式1&#xff1a;最新版的 先找到 anaconda 安装目录下的 condabin/conda &#xff0c;然后加载环境&#xff0c; 加载之后下面就有了conda环境&#xff0c;可以进行选择 方式2&#xff1a; 在一台新电脑上配置anaconda环境时&#xff0c;发现pycharm在设置解释器时&#x…

探索前端框架的未来:Svelte 的崛起

引言 在前端开发的世界里&#xff0c;框架更新换代的速度仿佛光速。从 jQuery 到 Angular&#xff0c;再到如今大热的 React 和 Vue&#xff0c;开发者们不断追逐更轻量、更快、更易于维护的框架。如今&#xff0c;Svelte 正悄然崛起&#xff0c;并引发了关于前端框架未来的热烈…

HTML开发常见错误排查技巧与浏览器兼容性解决方案

系列文章目录 01-从零开始学 HTML&#xff1a;构建网页的基本框架与技巧 02-HTML常见文本标签解析&#xff1a;从基础到进阶的全面指南 03-HTML从入门到精通&#xff1a;链接与图像标签全解析 04-HTML 列表标签全解析&#xff1a;无序与有序列表的深度应用 05-HTML表格标签全面…

ctf网络安全大赛python ctf网络安全大赛

ctf 网络安全比赛 CTF&#xff08;CaptureTheFlag&#xff09;中文一般译作夺旗赛&#xff0c;在网络安全领域中指的是网络安全技术人员之间进行技术竞技的一种比赛形式。CTF起源于1996年DEFCON全球黑客大会&#xff0c;以代替之前黑客们通过互相发起真实攻击进行技术比拼的方式…

Github - 记录一次对“不小心包含了密码的PR”的修复

Github - 记录一次对“不小心包含了密码的PR”的修复 前言 和好朋友一起开发一个字节跳动青训营抖音电商后端(now private)的项目&#xff0c;某大佬不小心把本地一密码commit上去并提了PR。 PR一旦发出则无法被删除&#xff0c;且其包含的commit也能被所有能看到这个仓库的…

自己做了个微信小游戏:推一个箱子

微信小程序搜&#xff1a;推一个箱子 里边目前有4个小游戏,喜欢的朋友帮忙点点&#xff0c;在此谢过 2个是我小时候玩文曲星上的经典小游戏 1.推箱子 2.猜数字 3.散光训练&#xff08;这个是刷短视频说能调节散光&#xff0c;不知道真的假的&#xff0c;然后就做了个工具&#…

Deepseek-v3 / Dify api接入飞书机器人go程序

准备工作 开通了接收消息权限的飞书机器人&#xff0c;例如我希望用户跟飞书机器人私聊&#xff0c;就需要开通这个权限&#xff1a;读取用户发给机器人的单聊消息 im:message.p2p_msg:readonly准备好飞书机器人的API key 和Secretdeepseek-v3的api keysecret&#xff1a;http…