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;
}
}
}