我正在尝试相对于像素大小平铺我的画布背景。这是我目前的代码...
我希望它看起来像这样... 我只想使用代码创建平铺的网格背景,而不想使用png或图像文件创建该网格。<Window x:Class="graph_view.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:graph_view"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="10"></TextBox>
<Canvas Grid.Row="1">
<Canvas.Background>
<DrawingBrush TileMode="Tile" Viewbox="0,0,20,20" ViewportUnits="RelativeToBoundingBox" AlignmentX="Left" AlignmentY="Top">
<DrawingBrush.Drawing>
<GeometryDrawing Brush="sc# 1.0, 0.02, 0.02, 0.02">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,20,20" />
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Thickness="1" Brush="red"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.Background>
</Canvas>
</Grid>
</Window>