我试图平铺我的画布相对于像素大小的背景。这是我目前有...WPF以像素为单位的平铺背景
我希望它看起来像这样... 我只是想创建使用代码背景平铺网格。我不想使用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>
真棒,正是我想要的。谢谢 – JokerMartini