Created
February 15, 2018 14:52
-
-
Save TinkerWorX/188d5617491c607c4f412b6f91dc8038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Application.Resources> | |
<loaders:XmlResourceLoader x:Key="GlobalProductClassifications" Path="data/external/Custom_GPCList.xml" Type="{x:Type gs1:Schema}" /> | |
</Application.Resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ListBox ItemsSource="{Binding Segments, Source={StaticResource GlobalProductClassifications}}" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class XmlResourceLoader : MarkupExtension | |
{ | |
public string Path { get; set; } | |
public Type Type { get; set; } | |
public object Value { get; private set; } | |
public override object ProvideValue(IServiceProvider serviceProvider) | |
{ | |
if (this.Value != null) | |
return this.Value; | |
try | |
{ | |
using (var stream = File.OpenText(this.Path)) | |
this.Value = new XmlSerializer(this.Type).Deserialize(stream); | |
} | |
catch (Exception e) | |
{ | |
Log.Error(e, "Error while deserializing '{path'} into '{type}'.", this.Path, this.Type); | |
} | |
return this.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment