namespace SilverlightConfigurationThroughXamlFile
{
public class Config
{
public Config()
{
SomeChildren = new List<ConfigChildren>();
}
public List<ConfigChildren> SomeChildren { get; set; }
public string MainSetting1 { get; set; }
public string MainSetting2 { get; set; }
public string MainSetting3 { get; set; }
public string MainSetting4 { get; set; }
}
public class ConfigChildren
{
public string Setting1 { get; set; }
public bool Setting2 { get; set; }
public int Setting3 { get; set; }
}
}
<local:Config xmlns:local="clr-namespace:SilverlightConfigurationThroughXamlFile;assembly=SilverlightConfigurationThroughXamlFile"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys='clr-namespace:System;assembly=mscorlib'
MainSetting1='test 1234' MainSetting2='ABCD 1234' MainSetting3='EFGH 1234' MainSetting4='IJKL 1234'>
<local:Config.SomeChildren >
<local:ConfigChildren
Setting1='Hello world' Setting2='true' Setting3='26' />
</local:Config.SomeChildren>
</local:Config>
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("/Config.xaml", UriKind.Relative));
}
The following supporting method also needs to be added to the same file:
private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Config config = (Config)XamlReader.Load(e.Result);
// this config object can later stored into an application level variable
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)