How to create repeating diagonal lines as background in WPF?

Ok, I destroyed my brain, Google and stackoverflow, trying to figure it out, but just can't get it. I am trying to use DrawingBrush with a DrawingGroup to do two things against the background of my WPF application (latest version). First, I want RadialGradientBrush to use a subtle gradient in my background. This part works just fine. The second part that I am trying to accomplish is that I also want to repeat the diagonal lines as part of this background. I know that I can do this with an image, but rather I will use geometry as I try to learn and master WPF. Here is what I still have. The radial color seems beautiful, but there are no lines. Any help would be appreciated.

<Style x:Key="WindowBackground" TargetType="Grid">
        <Setter Property="Background">
            <Setter.Value>
                <DrawingBrush>
                    <DrawingBrush.Drawing>
                        <DrawingGroup>
                            <GeometryDrawing>
                                <GeometryDrawing.Brush>
                                    <RadialGradientBrush GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
                                        <GradientStop Color="#EE9D40" Offset="0"/>
                                        <GradientStop Color="#BF8230" Offset="1"/>
                                    </RadialGradientBrush>
                                </GeometryDrawing.Brush>
                                <GeometryDrawing.Geometry>
                                    <RectangleGeometry Rect="0,0,1,1"/>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                            <GeometryDrawing>
                                <GeometryDrawing.Brush>
                                    <DrawingBrush TileMode="Tile" Stretch="None" Viewbox="0,0,1,1" Viewport="0,0,25,25" ViewportUnits="Absolute">
                                        <DrawingBrush.RelativeTransform>
                                            <TranslateTransform X="0" Y="0" />
                                        </DrawingBrush.RelativeTransform>
                                        <DrawingBrush.Drawing>
                                            <GeometryDrawing Brush="#20FFFFFF" Geometry="M10,0 22,0 12,25 0,22 Z" />
                                        </DrawingBrush.Drawing>
                                    </DrawingBrush>
                                </GeometryDrawing.Brush>
                                <GeometryDrawing.Geometry>
                                    <RectangleGeometry Rect="0,0,1,1"/>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                        </DrawingGroup>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </Setter.Value>
        </Setter>
    </Style>
+5
3

.

<LinearGradientBrush EndPoint="0,0" StartPoint="8,8" 
                     MappingMode="Absolute" SpreadMethod="Repeat">
    <GradientStop Color="Black" Offset="0" />
    <GradientStop Color="Black" Offset="0.1" />
    <GradientStop Color="White" Offset="0.1" />
    <GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
+16

- , , . :

<Style x:Key="WindowBackground" TargetType="Grid">
            <Setter Property="Background">
                <Setter.Value>
                    <RadialGradientBrush GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
                        <GradientStop Color="#EAA659" Offset="0"/>
                        <GradientStop Color="#BF8230" Offset="1"/>
                    </RadialGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="HatchOverlay" TargetType="Rectangle">
            <Setter Property="Fill">
                <Setter.Value>
                    <VisualBrush Opacity=".1" TileMode="Tile" Viewport="0,0,10,20" ViewportUnits="Absolute">
                        <VisualBrush.Visual>
                            <Canvas>
                                <Path Stroke="#825821" Data="M 0 0 l 10 20" />
                            </Canvas>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </Setter.Value>
            </Setter>
        </Style>

, , , :

<Grid Style="{StaticResource WindowBackground}">
    <Rectangle Style="{StaticResource HatchOverlay}"/>...

, . ; .

+1
  • Try rotating the horizontal brush to avoid corner gaps:

    <VisualBrush TileMode="Tile" 
     Viewport="0,0,5,5" ViewportUnits="Absolute" 
     Viewbox="0,0,5,5"  ViewboxUnits="Absolute">
     <VisualBrush.Visual>
        <Grid Background="White" Height="5">
            <Path Stroke="Black" Data="M 0 3 l 8 0" />
        </Grid>
     </VisualBrush.Visual>
     <VisualBrush.RelativeTransform>
         <RotateTransform CenterX="0.5" CenterY="0.5" Angle="45" />
     </VisualBrush.RelativeTransform>
    </VisualBrush>
    
+1
source

All Articles