0

我正在寻找制作of的最佳pattern方法。我想用画线显示用户画布,它将显示不同大小文档的边框,例如纸 A4。我是通过在 XAML 中使用来实现的。这是我的代码:backgroundcanvasDrawingBrush

<DrawingBrush x:Key="BackgroundPattern" ViewportUnits="Absolute" Stretch="None" TileMode="Tile">
        <DrawingBrush.Viewport>
            <Rect X="0" Y="0" Width="1089" Height="1842"/>
        </DrawingBrush.Viewport>
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <GeometryDrawing Brush="Blue">
                    <GeometryDrawing.Geometry>
                        <GeometryGroup>
                            <RectangleGeometry>
                                <RectangleGeometry.Rect>
                                    <Rect X="0" Y="0" Width="1089" Height="1842"/>
                                </RectangleGeometry.Rect>
                            </RectangleGeometry>
                        </GeometryGroup>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
                <GeometryDrawing Brush="#FFB9B9B9">
                    <GeometryDrawing.Geometry>
                        <GeometryGroup>
                            <RectangleGeometry>
                                <RectangleGeometry.Rect>
                                    <Rect X="1" Y="1" Width="1088" Height="1841"/>
                                </RectangleGeometry.Rect>
                            </RectangleGeometry>
                        </GeometryGroup>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>

我在tile模式下使用这个刷子,有效果: 在此处输入图像描述

我害怕我的元素的大小 -Viewport大小是 1089x1842。还有其他方法可以制作这些吗?

4

1 回答 1

1

尽管 WPF 绘图的大小无关紧要(因为它不是位图),但您可以像这样简化它:

<DrawingBrush x:Key="BackgroundPattern" ViewportUnits="Absolute" Viewport="0,0,1089,1842"
    AlignmentX="Left" AlignmentY="Top" Stretch="None" TileMode="Tile">
    <DrawingBrush.Drawing>
        <GeometryDrawing Brush="#FFB9B9B9">
            <GeometryDrawing.Pen>
                <Pen Thickness="1" Brush="Blue"/>
            </GeometryDrawing.Pen>
            <GeometryDrawing.Geometry>
                <RectangleGeometry Rect="0,0,1089,1842"/>
            </GeometryDrawing.Geometry>
        </GeometryDrawing>
    </DrawingBrush.Drawing>
</DrawingBrush>
于 2015-10-28T10:24:34.250 回答