From afd25d7b98dc4af60710c848479701104a85d00a Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 15 Sep 2015 18:59:27 +0300 Subject: [PATCH] Try to load .paml if .xaml wasn't found --- .../Perspex.Markup.Xaml/PerspexXamlLoader.cs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs b/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs index a2e7cfbabe..cf8409d5e9 100644 --- a/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs +++ b/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; +using System.Collections.Generic; +using System.IO; using System.Reflection; using OmniXaml; using Perspex.Markup.Xaml.Context; @@ -52,7 +54,27 @@ namespace Perspex.Markup.Xaml /// The loaded object. public object Load(Type type, object rootInstance = null) { - return Load(GetUriFor(type), rootInstance); + var assetLocator = Locator.Current.GetService(); + if (assetLocator == null) + { + throw new InvalidOperationException( + "Could not create IAssetLoader : maybe Application.RegisterServices() wasn't called?"); + } + foreach (var uri in GetUrisFor(type)) + { + Stream stream; + try + { + stream= assetLocator.Open(uri); + } + catch (FileNotFoundException) + { + continue; + } + using (stream) + return Load(stream, rootInstance); + } + throw new FileNotFoundException("Unable to find view for " + type.FullName); } /// @@ -84,7 +106,7 @@ namespace Perspex.Markup.Xaml /// /// The type. /// The URI. - private static Uri GetUriFor(Type type) + private static IEnumerable GetUrisFor(Type type) { if (type.Namespace != null) { @@ -97,10 +119,9 @@ namespace Perspex.Markup.Xaml replace = replace + "/"; } - return new Uri(replace + type.Name + ".xaml", UriKind.Relative); + foreach (var ext in new[] {".xaml", ".paml"}) + yield return new Uri(replace + type.Name + ext, UriKind.Relative); } - - return null; } } }