Wpf 画特殊背景

Wpf 画特殊背景,wpf,Wpf,在WPF中是否可以按以下方式绘制窗口的背景: 例如,窗口的背景是白色的 宽度为20像素的垂直彩色线条之间具有相同的大小间隙,这样您就可以得到红色条纹图案 同一颜色中高度为20像素的水平彩色线条,中间也有相同的大小间隙 水平和垂直红线相互重叠的区域应再次显示为白色,以便获得一种棋盘格图案 我知道如何在WPF中绘制线条,我知道如何重复绘制以填充整个背景,但我不知道如何管理重叠颜色消失的零件。不确定间隙应该有多大。但是,您可以如下方式调整绘图笔刷: <Window.Background>

在WPF中是否可以按以下方式绘制窗口的背景:

  • 例如,窗口的背景是白色的
  • 宽度为20像素的垂直彩色线条之间具有相同的大小间隙,这样您就可以得到红色条纹图案
  • 同一颜色中高度为20像素的水平彩色线条,中间也有相同的大小间隙
  • 水平和垂直红线相互重叠的区域应再次显示为白色,以便获得一种棋盘格图案

我知道如何在WPF中绘制线条,我知道如何重复绘制以填充整个背景,但我不知道如何管理重叠颜色消失的零件。

不确定间隙应该有多大。但是,您可以如下方式调整绘图笔刷:

<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>

不确定间隙应该有多大。但是,您可以如下方式调整绘图笔刷:

<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>


矩形几何图形的作用是什么?至少在第一个版本中,我可以在不改变结果背景的情况下删除它?它是白色背景。没有它,背景将是透明的。
矩形几何体是做什么的?至少在第一个版本中,我可以在不改变结果背景的情况下删除它?它是白色背景。没有它,背景将是透明的。