Since my last post «MahApps HamburgerMenu & PowerShell»,
some people asked me on how to use the version with an image and not the canvas
resources available in Icons.xaml.
To achieve this, in this post
I’ll show you:
- How to set up your
project files.
- What needs to be changed
compared to the previous version.
Here is a little preview of
what you’ll get at the end:
Setting up your project:
Compared to the previous project, the structure hasn’t changed. I just added the “Assets” folder in which all images are stored.
What needs to be changed?
- XAML side:
Replace the data template for HamburgerMenuIconItem in Grid.Resources with the data template for HamburgerMenuImageItem below.
The Item will no longer be
created from a canvas but a thumbnail specified in the Items source.
In the HamburgerMenu
control, for each item collection replace these lines:
With:
As you can see, I replaced
the control with HamburgerMenuImageItem and also got rid of the Icon
attribute. There is also a new tag if you have noticed , it’s there that we’ll put the path for images.
Lastly, there is the
content. It’s not mandatory, I just did so because I wanted to have the content
of my “Views” and get the images sawn on thumbnail in the background.
- PowerShell Side:
Inside the script, there
is not that much modifications to do. You just need to replace the filename in
your scripts if you have edited them.
$XamlChildWindow =
LoadXaml($viewFolder+"\Mountain.xaml")
$Childreader = (New-Object System.Xml.XmlNodeReader $XamlChildWindow)
$MountainXaml = [Windows.Markup.XamlReader]::Load($Childreader)
$MountainView.Children.Add($MountainXaml)
| Out-Null
And that’s it, now you
should have the same result as presented above. Thanks for reading and hope it
will help you 😊
All files are available
here for download.
0 commentaires:
Post a Comment