WPF背景模式

时间:2015-10-28 09:50:07

标签: c# wpf drawingbrush

我正在寻找为pattern background canvas寻找DrawingBrush的最佳方法。我想用绘制的线条显示用户画布,这将显示不同大小的文档的边框,例如纸A4。 我在XAML中使用<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模式下使用此画笔,有效: enter image description here

我害怕元素的大小 - try { def http = new HTTPBuilder('http://localhost:8080/MyApplication2') http.get( path : '/ControllerName/Action', contentType : ContentType.TEXT) { resp, reader -> println "response status: ${resp.statusLine}" resp.headers.each { h -> println " ${h.name} : ${h.value}" } } } catch (groovyx.net.http.HttpResponseException ex) { ex.printStackTrace() println ex.toString() } catch (java.net.ConnectException ex) { ex.printStackTrace() println ex.toString() } 大小为1089x1842。有没有其他方法来制作这些?

1 个答案:

答案 0 :(得分: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>