summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-07-19 01:17:29 +0200
committerJason Smith <jason.smith@xamarin.com>2016-07-18 16:17:29 -0700
commitf304f25df2d80094d2c31fda4986f92454599a7e (patch)
treee9b9a32bea7e5f8c5e07fbcb4cabbaa5abb0c2f8 /Xamarin.Forms.Xaml
parent272033723ea275ceb8a288fa605eafd035c79f2d (diff)
downloadxamarin-forms-f304f25df2d80094d2c31fda4986f92454599a7e.tar.gz
xamarin-forms-f304f25df2d80094d2c31fda4986f92454599a7e.tar.bz2
xamarin-forms-f304f25df2d80094d2c31fda4986f92454599a7e.zip
[Xaml] allow the Previewer to provide their own Xaml files for any type (#262)
* [Xaml] allow the Previewer to provide their own Xaml files for any type * [Xaml] use a Func instead of an interface, easier to use by reflection. Add tests * [XamlC] move the InitializeComponent duplication to XamlC task * [XamlC] generate branching code * [XamlC] fix the XamlC issue * [XamlC] make the API public * [docs] fix docs
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/XamlLoader.cs22
1 files changed, 20 insertions, 2 deletions
diff --git a/Xamarin.Forms.Xaml/XamlLoader.cs b/Xamarin.Forms.Xaml/XamlLoader.cs
index 37bea4e4..40414092 100644
--- a/Xamarin.Forms.Xaml/XamlLoader.cs
+++ b/Xamarin.Forms.Xaml/XamlLoader.cs
@@ -33,6 +33,15 @@ using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml;
+namespace Xamarin.Forms.Xaml.Internals
+{
+ public static class XamlLoader
+ {
+ public static Func<Type, string> XamlFileProvider { get; internal set; }
+ internal static bool DoNotThrowOnExceptions { get; set; }
+ }
+}
+
namespace Xamarin.Forms.Xaml
{
internal static class XamlLoader
@@ -64,12 +73,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 = Xamarin.Forms.Xaml.Internals.XamlLoader.DoNotThrowOnExceptions
+ });
break;
}
}
}
+ [Obsolete ("Use the XamlFileProvider to provide xaml files. We will remove this when Cycle 8 hits Stable.")]
public static object Create (string xaml, bool doNotThrow = false)
{
object inflatedView = null;
@@ -113,6 +126,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 (Xamarin.Forms.Xaml.Internals.XamlLoader.XamlFileProvider != null && (xaml = Xamarin.Forms.Xaml.Internals.XamlLoader.XamlFileProvider(type)) != null)
+ return xaml;
+
var assembly = type.GetTypeInfo().Assembly;
string resourceId;
@@ -129,7 +148,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))