VisualBrush template in xaml

essamce 621 Reputation points
2020-04-28T20:18:18.337+00:00

hi
i'm creating a lib of hatch patterns as VisualBrush as a resource dictionary,
every things goes well so far, i have some questions ,
here is my code:

 <VisualBrush
         x:Key="VisualBrush.Hatch.Fill"
         TileMode="Tile"
         Viewbox="0,0,15,15"
         ViewboxUnits="Absolute"
         Viewport="0,0,15,15"
         ViewportUnits="Absolute">
            <VisualBrush.Visual>
                <Grid Background="Transparent">
                    <Path Data="M 0 15 L 15 0" Stroke="Gray" />
                    <Path Data="M 0 0 L 15 15" Stroke="Gray" />
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>

        <VisualBrush
         x:Key="VisualBrush.Hatch.Clay"
         TileMode="Tile"
         Viewbox="0,0,15,15"
         ViewboxUnits="Absolute"
         Viewport="0,0,15,15"
         ViewportUnits="Absolute">
            <VisualBrush.Visual>
                <Grid Background="Transparent">
                    <Path Data="M 0 15 L 15 0" Stroke="Gray" />
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>

        <VisualBrush
         x:Key="VisualBrush.Hatch.Silt"
         TileMode="Tile"
         Viewbox="0,0,10,10"
         ViewboxUnits="Absolute"
         Viewport="0,0,10,10"
         ViewportUnits="Absolute">
            <VisualBrush.Visual>
                <Grid Background="Transparent">
                    <Path
                     Data="M 5 0 L 0 5"
                     Stroke="Black"
                     StrokeThickness="0.5" />
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>

Q1: i want to do something similar to Style(or template) to extract the repeated (below) code out of each pattern.
// repeated code
TileMode="Tile"
Viewbox="0,0,15,15"
ViewboxUnits="Absolute"
Viewport="0,0,15,15"
ViewportUnits="Absolute"

Q2: i want to know what is the are the Viewport/ViewBox and what is the difference .
Q3: i want to know how to scale the pattern instead of define another one .

thanks in advance

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,667 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Li-MSFT 1,096 Reputation points
    2020-04-29T03:14:32.5+00:00

    Welcome to our Microsoft Q&A platform!

    Q1:

    Do you want to get the property of VisualBrush?

    7754-untitled.png

    Q2:
    see the following MSDN link

    viewbox

    viewport

    Q3:

    learn about how-to-scale-an-element

    Thanks.

    1 person found this answer helpful.