I have a ResourceDictionary in a xaml file that represents a skin in a folder on my hard drive in some random folder. Say D: \ Temp2 \ BlackSkin.xaml.
I set permissions correctly to provide full access so that there is no problem.
This ResourceDictionary BlackSkin.xaml refers to BaseSkin.xaml like this:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="{D:\Temp2\BaseSkin.xaml">
</ResourceDictionary.MergedDictionaries>
So, I download this BlackSkin.xaml using XamlReader.Load (...)
It works fine if I put:
Source="D:\Temp2\BaseSkin.xaml"/>
, , . , , (BlackSkin.xaml)... aka "D:\Temp2\BaseSkin.xaml"...or... "BaseSkin.xaml", , , .
? , ? "" - .cs ? XamlReader.Load(...)?
Custom Markup Extension , - ProvideValue?
?
, XamlReader.Load(fileStream) :
public void ApplySkin(string fileName, string baseSkinFileName)
{
if (File.Exists(baseSkinFileName))
{
ResourceDictionary baseSkinDictionary = null;
using (FileStream baseSkinStream = new FileStream(baseSkinFileName, FileMode.Open))
{
baseSkinDictionary = (ResourceDictionary)XamlReader.Load(baseSkinStream);
baseSkinStream.Close();
}
using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
{
ResourceDictionary skinDictionary = (ResourceDictionary)XamlReader.Load(fileStream);
skinDictionary.MergedDictionaries.Add(baseSkinDictionary);
Resources.MergedDictionaries.Clear();
Resources.MergedDictionaries.Add(skinDictionary);
fileStream.Close();
}
, , BaseSkin.xaml BlackSkin.xaml... BaseSkin.xaml?
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="{StaticResource baseSkin}"/>
</ResourceDictionary.MergedDictionaries>
, , , BlackSkin.xaml, - ? , , , , , , , ResourceDictionary, , , xaml.
.
EDIT:
, , XamlParseException, , , clr, , - - , .
, Xaml, , , , , , , ...?
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:TimersXP.Extensions">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="{base:BaseSkinPath}"/>
</ResourceDictionary.MergedDictionaries>
, , , , . - ?
:
http://tech.pro/tutorial/883/wpf-tutorial-fun-with-markup-extensions
using System;
using System.Windows.Markup;
namespace TimersXP.Extensions
{
class BaseSkin : MarkupExtension
{
public string BaseSkinPath
{
get { return "D:\\Temp2\\BaseSkin.xaml"; }
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return "D:\\Temp2\\BaseSkin.xaml";
}
}
}