summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-07-18 10:00:06 +0200
committerStephane Delcroix <stephane@delcroix.org>2016-07-18 10:00:06 +0200
commit962c8fd352e32309c9dcb7f8c2f07a335f18fc75 (patch)
treee32ba75871fed7738b5b696d72a412e95cc9d025 /Xamarin.Forms.Xaml
parentf7deeece812c9f20f054d239ec3dd6e3700dc254 (diff)
downloadxamarin-forms-962c8fd352e32309c9dcb7f8c2f07a335f18fc75.tar.gz
xamarin-forms-962c8fd352e32309c9dcb7f8c2f07a335f18fc75.tar.bz2
xamarin-forms-962c8fd352e32309c9dcb7f8c2f07a335f18fc75.zip
[Xaml] allow the Previewer to provide their own Xaml files for any type
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/IXamlFileProvider.cs9
-rw-r--r--Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj1
-rw-r--r--Xamarin.Forms.Xaml/XamlLoader.cs15
3 files changed, 23 insertions, 2 deletions
diff --git a/Xamarin.Forms.Xaml/IXamlFileProvider.cs b/Xamarin.Forms.Xaml/IXamlFileProvider.cs
new file mode 100644
index 00000000..7f989019
--- /dev/null
+++ b/Xamarin.Forms.Xaml/IXamlFileProvider.cs
@@ -0,0 +1,9 @@
+´╗┐using System;
+
+namespace Xamarin.Forms.Xaml
+{
+ public interface IXamlFileProvider
+ {
+ string GetXamlFor(Type type);
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj b/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj
index cb4577c9..0081f67c 100644
--- a/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj
+++ b/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj
@@ -81,6 +81,7 @@
<Compile Include="ExpandMarkupsVisitor.cs" />
<Compile Include="XamlCompilationAttribute.cs" />
<Compile Include="TypeArgumentsParser.cs" />
+ <Compile Include="IXamlFileProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
diff --git a/Xamarin.Forms.Xaml/XamlLoader.cs b/Xamarin.Forms.Xaml/XamlLoader.cs
index 37bea4e4..e0dd894f 100644
--- a/Xamarin.Forms.Xaml/XamlLoader.cs
+++ b/Xamarin.Forms.Xaml/XamlLoader.cs
@@ -38,6 +38,8 @@ namespace Xamarin.Forms.Xaml
internal static class XamlLoader
{
static readonly Dictionary<Type, string> XamlResources = new Dictionary<Type, string>();
+ internal static bool DoNotThrowOnExceptions { get; set; }
+ internal static IXamlFileProvider XamlFileProvider { get; set; }
public static void Load(object view, Type callingType)
{
@@ -64,12 +66,16 @@ namespace Xamarin.Forms.Xaml
var rootnode = new RuntimeRootNode (new XmlType (reader.NamespaceURI, reader.Name, null), view, (IXmlNamespaceResolver)reader);
XamlParser.ParseXaml (rootnode, reader);
- Visit (rootnode, new HydratationContext { RootElement = view });
+ Visit (rootnode, new HydratationContext {
+ RootElement = view,
+ DoNotThrowOnExceptions = XamlLoader.DoNotThrowOnExceptions
+ });
break;
}
}
}
+ [Obsolete ("Use the XamlFileProvider to provide xaml files")]
public static object Create (string xaml, bool doNotThrow = false)
{
object inflatedView = null;
@@ -113,6 +119,12 @@ namespace Xamarin.Forms.Xaml
static string GetXamlForType(Type type)
{
+ string xaml = null;
+
+ //the Previewer might want to provide it's own xaml for this... let them do that
+ if (XamlFileProvider != null && (xaml = XamlFileProvider.GetXamlFor(type)) != null)
+ return xaml;
+
var assembly = type.GetTypeInfo().Assembly;
string resourceId;
@@ -129,7 +141,6 @@ namespace Xamarin.Forms.Xaml
// first pass, pray to find it because the user named it correctly
- string xaml = null;
foreach (var resource in resourceNames)
{
if (ResourceMatchesFilename(assembly, resource, likelyResourceName))