欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > 71.StackPanel黑白棋盘 WPF例子 C#例子

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

2025/6/16 4:19:21 来源:https://blog.csdn.net/S13461120713/article/details/145478692  浏览:    关键词: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>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词