Back when I was working with WPF more
(and if I recall correctly) the image resources were defined in
our code as DrawingImage/GeometryDrawing instead of Viewbox, which
you could bind to Image.Source, there may be a tool out there to
convert those VS files.
The markup method though is as you
suggest, throw all viewbox elements into a ResourceDictionary and
give each viewbox a resource key, then merge that resource
dictionary into Window.Resources of each window xaml definition,
or if you don't want to do that for each window add them to the
app resources in the App.xaml file.
The resource dictionary option looks like this:
MyResourceDictionary.xaml -
<ResourceDictionary
xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox x:Key="AddDocument" x:Shared="false" ... />
</ResourceDictionary>
MainWindow.xaml -
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="MyResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File" >
<MenuItem Header="_New" Icon="{StaticResource
AddDocument}" />
</MenuItem>
</Menu>
</DockPanel>
Folks, in a video I saw a few weeks ago I learned
that the Visual Studio team uses XAML for most of their images,
not png or similar. I'm keen to do the same because I imagine
that I would no longer need tedious sets of 16x16 32x32 48x48
... etc images because each XAML file is composed from scalable
geometry elements that would look good at any size.
I downloaded the
Image Library which contains
thousands of XAML, png and svg sets of standard images. But I
can't figure out how to
simply use the XAML files in a
WPF app. All the examples I can find seem to have pasted the
contents of the XAML images into resource files and then
reference them by x:Key. I don't want to manually paste XAML
around like that, I just want to add a file like
FolderClosedBlue.xaml (for
example) to my project and use it as the icon for a menu or
button as simply as possible. How can I replace this sort of
thing?...
<MenuItem Header="_Foo Command"
Command="...">
<MenuItem.Icon>
< use the XAML image file
somehow instead of a resource png? >
</MenuItem.Icon>
</MenuItem>
Is there some coding trick I'm not aware of to simply use
an image defined in a XAML file in my app?
Cheers, Greg K