question

essamce avatar image
0 Votes"
essamce asked AlexLi-MSFT commented

VisualBrush template in xaml

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=&#34;Tile&#34;
Viewbox=&#34;0,0,15,15&#34;
ViewboxUnits=&#34;Absolute&#34;
Viewport=&#34;0,0,15,15&#34;
ViewportUnits=&#34;Absolute&#34;

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-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AlexLi-MSFT avatar image
1 Vote"
AlexLi-MSFT answered AlexLi-MSFT commented

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.


untitled.png (12.2 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi @AlexLi-MSFT ,thanks for reply.
Q1: i wanna do it in xaml not in code behind cuz i'm creating resource dictionary,
Q2: the links u mentioned helps alot, thank u,
Q3: is it possible to scale the hatch in runtime?

0 Votes 0 ·

Q1:How do you want to get resource?

1 Vote 1 ·