How To Transform this VisualBrush by 180 degrees WPF - wpf

<DrawingBrush x:Key="AFT_SOUTH_HIT" Stretch="Uniform"
Drawing="{Binding Drawing, Source={StaticResource AFT_NORTH_HIT}}" >
</DrawingBrush>
I have a very complicated Definition for the DrawingBrush NAMED "AFT_NORTH_HIT"
My hope is to Transform this by 180 degrees into a new StaticResource "AFT_SOUTH_HIT". There will be one BRUSH per Geographical direction [N, S, E W]. I have tried attaching a TransformGroup as a child but I am not sure how to do this.
I have transformed other things but never a DrawingBrush. Thanks in Advance.
<DrawingBrush x:Key="AFT_NORTH_HIT" Stretch="Uniform">
<DrawingBrush.Drawing >
<DrawingGroup ClipGeometry="F1 M 0,0L 30,0L 30,14.4438L 0,14.4438L 0,0">
<DrawingGroup.Children>
<GeometryDrawing Brush="#FF46A5AA" Geometry="F1 M 15,8.77124C 7.14633,8.77124 0.696533,4.94452 0,0.0601196L 30,0.0601196C 29.3035,4.94452 22.8537,8.77124 15,8.77124 Z " />
<GeometryDrawing Brush="#FFFF0000" Geometry="F1 M 17.8936,0.124878L 20.1033,2.33459L 7.99411,14.4438L 5.78439,12.2341L 17.8936,0.124878 Z " />
<GeometryDrawing Brush="#FFFF0000" Geometry="F1 M 6.47174,2.20972L 8.68146,0L 20.7906,12.1092L 18.5809,14.3189L 6.47174,2.20972 Z " />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>

Tell if this solves your problem :
<DrawingBrush Stretch="Uniform">
<DrawingBrush.RelativeTransform>
<TransformGroup>
<RotateTransform Angle="180" CenterY="0.5" CenterX="0.5"/>
</TransformGroup>
</DrawingBrush.RelativeTransform>

Related

Fixing blurred lines that are drawn by DrawingBrush

This is my drawing brush:
<DrawingBrush x:Key="GridBrush" TileMode="Tile"
Viewport="0,0,60,30" ViewportUnits="Absolute"
Viewbox="0,0,60,30" ViewboxUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<GeometryGroup>
<LineGeometry EndPoint="0,30"/>
<LineGeometry EndPoint="60,0"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Brush="DarkGray" Thickness="1" DashCap="Flat" >
<Pen.DashStyle>
<DashStyle Dashes="2,2"/>
</Pen.DashStyle>
</Pen>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
This is where I use it:
<Border Width="721" Background="{StaticResource GridBrush}" UseLayoutRounding="True" SnapsToDevicePixels="True" >
And the effects is:
Basically the middle line is "okish" the other two are wider then they should. I tried using UseLayoutRounding, SnapsToDevicePixels but with or without those options nothing changes. I ran out of ideas by now :/

How to show drawing brush as a Menu item Icon

I need to show drawing brush as MenuItem icon.
Following is the drawing brush
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DrawingBrush x:Key="NewDocument" Stretch="Uniform">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M 41.3333,41.3333L 0,41.3333L 0,0L 41.3333,0L 41.3333,41.3333 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 15.8164,7.40293L 15.8164,1.85626L 13.9991,1.85626L 13.9991,7.40293C 14.2964,7.35093 14.5951,7.31093 14.9071,7.31093C 15.2191,7.31093 15.5177,7.35093 15.8164,7.40293 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 21.1491,3.7708L 19.5731,2.86147L 16.7997,7.6668C 17.3784,7.88413 17.9024,8.19614 18.3704,8.5828L 21.1491,3.7708 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 24.8099,8.09827L 23.9005,6.52493L 19.0885,9.30227C 19.4765,9.76893 19.7899,10.2929 20.0045,10.8756L 24.8099,8.09827 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 8.66667,21.7579L 10.2413,22.6672L 13.0147,17.8619C 12.436,17.6472 11.912,17.3352 11.444,16.9459L 8.66667,21.7579 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 5.00454,17.4343L 5.91387,19.0076L 10.7272,16.2289C 10.3392,15.7623 10.0259,15.2396 9.8112,14.6596L 5.00454,17.4343 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 9.54493,11.8561L 3.9996,11.8561L 3.9996,13.6735L 9.54493,13.6735C 9.49559,13.3788 9.45426,13.0748 9.45426,12.7655C 9.45426,12.4548 9.49559,12.1521 9.54493,11.8561 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 5.914,6.52533L 5.00467,8.09866L 9.81,10.8747C 10.0247,10.2933 10.338,9.76934 10.726,9.30266L 5.914,6.52533 Z "/>
<GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 10.2409,2.86134L 8.66627,3.77067L 11.4449,8.584C 11.9116,8.196 12.4356,7.884 13.0156,7.66666L 10.2409,2.86134 Z "/>
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M 25.3333,25.3333L 25.3333,14.6667L 17.3333,14.6667L 17.3333,38.6667L 36,38.6667L 36,25.3333L 25.3333,25.3333 Z "/>
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M 28,14.6667L 28,22.6667L 36,22.6667L 28,14.6667 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</ResourceDictionary>
I need to show it as a Menu Item Icon.
I tried the followinng way
<MenuItem
Header="New" Command="{Binding New}" >
<MenuItem.Icon >
<Image Source="Resources/Icons/NewDocument.xaml"/>
</MenuItem.Icon>
</MenuItem>
looking for a solution .Please help.
<MenuItem.Icon>
<Rectangle Fill="{StaticResource NewDocument}" Stretch="Uniform" >
</Rectangle>
</MenuItem.Icon>
This will work

Graph paper with elongated grid sections?

I am trying to make some Graph Paper using WPF using the DrawingBrush.
I found the following example on MSDN which is pretty close to what I want but not exactly. I want to do this is pure XAML. I am fairly new to WPF.
<DrawingBrush x:Key="GridTile"
Viewport="0,0,10,10"
ViewportUnits="Absolute"
TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Geometry="M0,0 L1,0 1,0.1, 0,0.1Z" Brush="Blue" />
<GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="Red" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
Currently this generates
I want to generate
with a width of 3cm and each row being 4mm
I will use this tile my background or rather the DrawingBrush TileMode takes care of that for me.
Change the size of the Brush so the Viewport has more height than width, and change the Geometry accordingly so the lines still appear 1px thick.
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" SizeToContent="WidthAndHeight">
<Window.Resources>
<DrawingBrush x:Key="GridTile" Viewport="0,0,4,16"
ViewportUnits="Absolute" TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Geometry="M0,0 L1,0 1,0.05 0,0.05Z" Brush="Black"/>
<GeometryDrawing Geometry="M0,0 L0,1 0.1,1 0.1,0Z" Brush="Black"/>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Window.Resources>
<Rectangle Height="512" Width="512" Stroke="Black" StrokeThickness="0"
Fill="{StaticResource GridTile}"/>
</Window>

How to make a brush that paints graph-paper-like squares for Windows Phone 8?

Here is the solution for WPF:
<DrawingBrush Viewport="0,0,20,20"
ViewportUnits="Absolute" TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Geometry="M0,0 L1,0 1,0.1, 0,0.1Z" Brush="LightBlue" />
<GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="LightBlue" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
But as I understand there is no DrawingBrush under WinPhone8.
You can use Path class instead of DrawingBrush.
Examples: msdn tutorial, geekCamp

Display DrawingBrush in canvas and keeping his proportions

I use the SharpVector to convert icon.svg to icon.xaml.
This program generate a DrawingBrush like :
<DrawingBrush x:Key="Plus">
<DrawingBrush.Drawing>
<DrawingGroup xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DrawingGroup x:Name="DrawingLayer">
<DrawingGroup.ClipGeometry>
<RectangleGeometry Rect="0,0,88.582672,88.582672" />
</DrawingGroup.ClipGeometry>
<GeometryDrawing x:Name="path3767" Brush="#FF4D4D4D">
<GeometryDrawing.Geometry>
<PathGeometry FillRule="Nonzero" Figures="M36.512901,88.58266L36.512901,51.833165 8.88026306711254E-07,51.833165 8.88026306711254E-07,36.47519 36.512901,36.47519 36.512901,-1.76623310039759E-05 52.069777,-1.76623310039759E-05 52.069777,36.47519 88.582677,36.47519 88.582677,51.833165 52.069777,51.833165 52.069777,88.58266z" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingGroup>
</DrawingBrush.Drawing>
for all my icons. But now i want to display my DrawingBrush in a Canvas.Background, it's ok with that :
<Grid Background="{DynamicResource Plus}" Height="200" Width="200" Margin="5">
But i want to keep picture proportions stock in the Rectangle Geometry, for example here Rect="0,0,88.582672,88.582672".
How i can do that?
Gat
Try setting the Stretch property of DrawingBrush to uniform:
<DrawingBrush x:Key="Plus" Stretch="Uniform">
...

Resources