Note that there are some explanatory texts on larger screens.

plurals
  1. POXamlReader with Images
    primarykey
    data
    text
    <p>I'm creating an application in WPF (.Net 3.5) that I want to be able to customize on a per-client basis. I abstracted out the resources to external xaml (theme) files. With the xaml file built as a <code>Page</code>, this works perfect.</p> <p>Now I want to use <code>XamlReader</code> to dynamically load the theme's xaml files. This way I can compile the application and others can customize the app (per client) without having to deal with re-compiling or having access to the source code. Here's a snapshot of what I'm doing:</p> <pre><code>Directory.GetFiles(pathToThemeDirectory).Each((file) =&gt; { using (Stream stream = new FileStream(file, FileMode.Open)) { var dir = Directory.GetCurrentDirectory(); var dict = XamlReader.Load(stream) as ResourceDictionary; Application.Current.Resources.MergedDictionaries.Add(dict); } }); </code></pre> <p>Now that seems to parse the Xaml correctly. However, I now receive an error that looks like this:</p> <pre><code>Cannot convert string '/Path/To/Image/File.ico' in attribute 'Icon' to object of type 'System.Windows.Media.ImageSource'. Cannot locate resource '/Path/To/Image/File.ico'. Error at object 'System.Windows.Setter' </code></pre> <p>I want to be able to change these resources per client (logo images, etc), so I have changed the build action from <code>Resource</code> to <code>None</code> and told it to Always copy to the output directory. </p> <p>Are there any suggestions on how to parse Xaml at runtime and change my configuration to get image resources that have the need to not be compiled in the assembly? Or am I completely off base and there is a way better way to achieve this theme customization?</p> <hr> <h2>Update:</h2> <p>Here's the exact line that is giving the error:</p> <pre><code>&lt;Style x:Key="MainWindow"&gt; &lt;Setter Property="Window.Icon" Value="/Assets/icon.ico" /&gt; &lt;/Style&gt; </code></pre> <p>But that is because this is the first asset loaded. Here's another example: </p> <pre><code>&lt;ImageBrush x:Key="NavigationBackgroundImage" ImageSource="Assets/bg.png" TileMode="Tile" Stretch="UniformToFill"/&gt; </code></pre> <p>These are just used in styles accessed via:</p> <pre><code>{StaticResource MainWindow} </code></pre> <p>or </p> <pre><code>{StaticResource NavigationBackgroundImage} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload