Update: 16:37 09/07/2010 – For a more fuller explanation of how to do this see this post - http://www.codeproject.com/KB/dotnet/xamlconfig.aspx?msg=3409766#xx3409766xx
The following code snippet shows an example of how to load a Configuration class, from an associated XAML file. This can be done in any application that is referencing the PresentationFramework assembly C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll. The benefits of this should be obvious with Visual Studio 2008, and Jet brains Reshaper 4.5 or greater providing free intellisense support.
private static Uri BuildDefaultConfigurationUri()
{
const string UriFormat = "/{0};component/{1}";
return
new Uri(
string.Format(
UriFormat, Assembly.GetExecutingAssembly().GetName().Name, "Configuration/MyConfigFile.xaml"),
UriKind.Relative);
}
Then configuration can simply be loaded as follows...
uri = BuildDefaultConfigurationUri();
this.configuration = (Configuration)Application.LoadComponent(uri);
Example configuration then could be...
<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="clr-namespace:MyNameSpace"
xmlns:b="clr-namespace:MyNameSpace.Bins"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<MyClass1 x:Name="Default" IsDefault="True">
<MyClass2 x:Name="Main">
<Property1>
<b:MyClass3 />
</Property1>
<Property2>
<b:MyClass4 />
<b:MyClass5/>
<b:MyClass6 />
</Property2>
</MyClass2>
</MyClass1>
</Configuration>