using System; using System.Collections.Generic; using Xamarin.Forms; namespace Samples { public partial class XamlPreviewPage : ContentPage { public XamlPreviewPage () { InitializeComponent (); editor.Text = @" "; editor.TextChanged += (sender, e) => DisplayXaml (); DisplayXaml (); } public void DisplayXaml () { try { var asm = typeof (Xamarin.Forms.Xaml.Internals.XamlTypeResolver).Assembly; var xamlLoaderType = asm.GetType ("Xamarin.Forms.Xaml.XamlLoader"); var loadArgTypes = new[] { typeof (object), typeof (string) }; var loadMethod = xamlLoaderType.GetMethod ("Load", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, System.Reflection.CallingConventions.Any, loadArgTypes, null); var contentView = new ContentView (); loadMethod.Invoke (null, new object[] { contentView, editor.Text }); results.Content = contentView; } catch (Exception ex) { results.Content = new Label { Text = ex.ToString (), }; } } } }