在WPF中是否可以通过以下方式绘制窗口背景:
我知道如何在WPF中绘制线条,也知道如何重复绘制以填充整个背景,但是我不知道如何管理重叠颜色的零件。
答案 0 :(得分:2)
不确定差距应该有多大。但是,您可以这样调整DrawingBrush:
<Window.Background>
<DrawingBrush TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,100,100">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,100,100"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing
Geometry="M50,0 L50,40 M50,60 L50,100 M0,50 L40,50 M60,50 L100,50">
<GeometryDrawing.Pen>
<Pen Brush="Red" Thickness="20"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Window.Background>
或使用另一个TileMode:
<Window.Background>
<DrawingBrush TileMode="FlipXY" ViewportUnits="Absolute" Viewport="0,0,50,50">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,50,50"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Geometry="M0,45 L40,45 M45,0 L45,40">
<GeometryDrawing.Pen>
<Pen Brush="Red" Thickness="10"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Window.Background>