我需要在WPF中繪製一個棋盤。我是WPF新手,在XAML中編寫一些工作代碼對我來說非常複雜。WPF chessboard - 如何在XAML中畫圖
到目前爲止,我讀到我應該使用TileBrush,但我真的不知道如何使用它。我還讀過一些人使用UniformGrid繪製板,但是我不知道如何以正確的順序填充網格的單元格。我用canvas來做所有的操作,所以我不知道我是否可以在canvas中使用uniformgrid。
我也希望董事會調整,如果我改變窗口的尺寸。
有沒有可能這樣做?
我需要在WPF中繪製一個棋盤。我是WPF新手,在XAML中編寫一些工作代碼對我來說非常複雜。WPF chessboard - 如何在XAML中畫圖
到目前爲止,我讀到我應該使用TileBrush,但我真的不知道如何使用它。我還讀過一些人使用UniformGrid繪製板,但是我不知道如何以正確的順序填充網格的單元格。我用canvas來做所有的操作,所以我不知道我是否可以在canvas中使用uniformgrid。
我也希望董事會調整,如果我改變窗口的尺寸。
有沒有可能這樣做?
這樣通過代碼實現的背後
http://www.c-sharpcorner.com/UploadFile/mahesh/391/
,如果你在XAML要使用UniformGrid
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
x:Class="WpfApplication9.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="600">
<Window.Resources>
<Color x:Key="BlackRes">Black</Color>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<UniformGrid Margin="29,29.5,23,32.5" Height="500">
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="White" Stroke="Black"/>
<Rectangle Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource BlackRes}"/>
</Rectangle.Fill>
</Rectangle>
</UniformGrid>
</Grid>
我加入XAML代碼,使用UniformGrid – 2010-08-14 12:18:12
使用Microsoft混合 – 2010-08-14 11:19:46