diff --git a/Samples/Samples.csproj b/Samples/Samples.csproj
index 98ffe10..effd0d6 100644
--- a/Samples/Samples.csproj
+++ b/Samples/Samples.csproj
@@ -32,9 +32,6 @@
DisplayAlertPage.xaml
-
- XamlPreviewPage.xaml
-
@@ -56,9 +53,6 @@
MSBuild:Compile
-
- MSBuild:UpdateDesignTimeXaml
-
diff --git a/Samples/XamlPreviewPage.xaml b/Samples/XamlPreviewPage.xaml
deleted file mode 100644
index a96fa29..0000000
--- a/Samples/XamlPreviewPage.xaml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Samples/XamlPreviewPage.xaml.cs b/Samples/XamlPreviewPage.xaml.cs
deleted file mode 100644
index 21f9318..0000000
--- a/Samples/XamlPreviewPage.xaml.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using Xamarin.Forms;
-
-namespace Samples
-{
- public partial class XamlPreviewPage : ContentPage
- {
- public XamlPreviewPage ()
- {
- InitializeComponent ();
-
- editor.Text = @"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-";
- editor.TextChanged += (sender, e) => DisplayXaml ();
- DisplayXaml ();
- }
-
- CancellationTokenSource lastCts = null;
-
- public void DisplayXaml ()
- {
- try {
- var cts = new CancellationTokenSource ();
- var token = cts.Token;
- lastCts?.Cancel ();
- lastCts = cts;
-
- 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 });
-
- if (!token.IsCancellationRequested) {
- results.Content = contentView;
- }
- }
- catch (OperationCanceledException) {
- }
- catch (Exception ex) {
- results.Content = new Label {
- TextColor = Color.DarkRed,
- FontSize = 12,
- Text = ex.ToString (),
- };
- }
- }
- }
-}
diff --git a/Samples/XamlPreviewPageSample.cs b/Samples/XamlPreviewPageSample.cs
index 0f38ff5..8f4bc2d 100644
--- a/Samples/XamlPreviewPageSample.cs
+++ b/Samples/XamlPreviewPageSample.cs
@@ -1,6 +1,7 @@
using System;
-
+using System.Threading;
using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
namespace Samples
{
@@ -10,8 +11,108 @@ namespace Samples
public Ooui.Element CreateElement ()
{
- var page = new XamlPreviewPage ();
+ var page = new XamlEditorPage ();
return page.GetOouiElement ();
}
}
+
+ public partial class XamlEditorPage : ContentPage
+ {
+ Editor editor;
+ ContentView results;
+
+ public XamlEditorPage ()
+ {
+ InitializeComponent ();
+
+ editor.Text = @"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+";
+ editor.TextChanged += (sender, e) => DisplayXaml ();
+ DisplayXaml ();
+ }
+
+ void InitializeComponent ()
+ {
+ var grid = new Grid ();
+
+ grid.RowDefinitions.Add (new RowDefinition { Height = GridLength.Auto });
+ grid.RowDefinitions.Add (new RowDefinition { Height = GridLength.Star });
+ grid.ColumnDefinitions.Add (new ColumnDefinition { Width = GridLength.Star });
+ grid.ColumnDefinitions.Add (new ColumnDefinition { Width = GridLength.Star });
+
+ editor = new Editor {
+ FontSize = 12,
+ FontFamily = "monospace",
+ };
+ editor.SetValue (Grid.ColumnProperty, 0);
+ editor.SetValue (Grid.RowProperty, 1);
+
+ results = new ContentView ();
+ results.SetValue (Grid.ColumnProperty, 1);
+ results.SetValue (Grid.RowProperty, 1);
+
+ var title = new Label {
+ Text = "XAML Editor",
+ FontSize = 24,
+ FontAttributes = FontAttributes.Bold,
+ Margin = new Thickness (8),
+ };
+ title.SetValue (Grid.ColumnProperty, 0);
+ title.SetValue (Grid.RowProperty, 0);
+
+ grid.Children.Add (title);
+ grid.Children.Add (editor);
+ grid.Children.Add (results);
+
+ Content = grid;
+ }
+
+ CancellationTokenSource lastCts = null;
+
+ public void DisplayXaml ()
+ {
+ try {
+ var cts = new CancellationTokenSource ();
+ var token = cts.Token;
+ lastCts?.Cancel ();
+ lastCts = cts;
+
+ var contentView = new ContentView ();
+ contentView.LoadFromXaml (editor.Text);
+
+ if (!token.IsCancellationRequested) {
+ results.Content = contentView;
+ }
+ }
+ catch (OperationCanceledException) {
+ }
+ catch (Exception ex) {
+ results.Content = new Label {
+ TextColor = Color.DarkRed,
+ FontSize = 12,
+ Text = ex.ToString (),
+ };
+ }
+ }
+ }
}