There is a better way.
You will have a separate file for each fragment of the clip, but not the shell that the site uses, a Canvas instance directly in the resource dictionary is not the best way to move forward. We will start with a ResourceDictionary , but we will do it something like this: -
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:YourApplication"> <ControlTemplate TargetType="local:XamlImage" x:Key="SomeImage"> <Viewbox> <Canvas> </Canvas> </Viewbox> </ControlTemplate> </ResourceDictionary>
This does two things: the ControlTemplate is first used to hold the image, this is a more efficient form of storage when the image can be used several times, for example, when the image is used as an icon.
Secondly, it uses Viewbox , which provides the promise of vector graphics, it allows you to scale the image to a specified size.
You need to add a new Templated Custom Control to the project and call it XamlImage . You do not need to do anything about it, it just has to exist.
For now, just add this resource dictionary to App.Xaml (this is unlikely where it will stay).
Now you can put this image on the page using: -
<local:XamlImage Template="{StaticResource contactnew}" />
Now there are several ways to move forward, depending on your real intentions and volumes, the scenarios change for me to comment exhaustively. So, take two extremes ...
If you have only a few images that you would like to select, you could simply create more files and add them to the MergedDictionaries application. However, the big side is that all of these Xamls images are parsed and loaded at application startup, which may be undesirable.
On the other hand, you may have a large library of classified Xaml images. In this case, you will want to place them in the folder structure and include a thumbnail of default size for each of them. An xml file to work as a directory, and then on-demand downloads Xaml files as needed. In this case, you can cut the ResourceDictionary from the files and have the ControlTemplate as the root element, use XamlReader to load the template, and then cache the template in your dictionary (possibly as part of the directory implementation).