If you’ve ever been stuck and have to go through what seems like a never-ending and time-consuming task just to create a WPF project, I’ve got you covered. Here’s a little trick I have up my sleeve that I’ve fed into my programming pattern. The first step is simply to work on creating a dictionary of methods that would entail the repeated or recurrent code; it would be great to be able to rely on them when you start working on your XAML.

Talking about important material that would come super handy, here’s some useable geometry material:

<

Geometry

x:Key=

“DownArrow”>M0,0 L1,0 0.5,1Z

</

Geometry>

<

Geometry

x:Key=

“UpArrow”>M0,1 L1,1 0.5,0Z

</

Geometry>

<

Geometry

x:Key=

“RightArrow”>M0,0 L1,0.5 0,1Z

</

Geometry>

<

Geometry

x:Key=

“LeftArrow”>M0,0.5 L1,1 1,0Z

</

Geometry>

<

Geometry

x:Key=

“CloseX”>M0,0 L1,1 M0,1 L1,0

</

Geometry>

Next, these will always be the underdogs of design – arrows, having quick access to them is always something I’ve been thankful for.

 

<!– DownArrow –>

<

Path

Data=

“{StaticResource DownArrow}”

Width=

“10”

Height=

“8”

Stretch=

“Fill”

Fill=

“Black”/>

<!– CloseX –>

<

Path

Data=

“{StaticResource CloseX}”

Width=

“12”

Height=

“12”

Stretch=

“Fill”

Stroke=

“Black”

StrokeThickness=

“3”

Margin=

“10”/>

If you were to try it out, they would come out to look like this:

The geometries are all present within a real coordinate space of a pixel, thus it is crucial to make sure to set the Stretch attribute to Fill, that way the geometry will extend to the size of the Path component.

If you’re searching for an alternative, as suggested by Dr.WPF, when it comes to Silverlight, instead of including materials as Geometries, attaching them as strings as shown:

<

Grid

xmlns=

“http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=

“http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:sys=

“clr-namespace:System;assembly=mscorlib”>

<

Grid.Resources>

<

sys:String

x:Key=

“DownArrow”>M0,0 L1,0 0.5,1Z

</

sys:String>

<

sys:String

x:Key=

“UpArrow”>M0,1 L1,1 0.5,0Z

</

sys:String>

<

sys:String

x:Key=

“RightArrow”>M0,0 L1,0.5 0,1Z

</

sys:String>

<

sys:String

x:Key=

“LeftArrow”>M0,0.5 L1,1 1,0Z

</

sys:String>

<

sys:String

x:Key=

“CloseX”>M0,0 L1,1 M0,1 L1,0

</

sys:String>

</

Grid.Resources>

</

Grid>

All you have to do now is go on as you would on a normal day, the usage from XAML is then the same as WPF.  Have fun creating!

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *