How to Preview XAML in Xamarin.Forms in Xamarin Sketches

Asked 3 months ago, Updated 3 months ago, 13 views

Xamarin Studio 5.6.3 build 3 uses Sketches functionality. I wish I could preview the XAML file when I use it in Xamarin.Forms mode, but unfortunately it doesn't seem to offer this feature.

Is there a good way?

xamarin

2022-09-30 12:06

1 Answers

The XAML loader provided by the method in Xamarin.Forms can be used by reflection. Paste the following code into the Sketches text area

using Xamarin.Forms;
using System.Reflection;
using System.Runtime.CompilerServices;
using Xamarin.Forms.Xaml;

var [email protected]"<?xml version="1.0""encoding="utf-8""?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms""xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml""x:Class="XamlSamples.HelloXamlPage""
             Title= "Hello XAML Page"
             Padding="10, 40, 10, 10" >

  <Label Text="Hello, XAML Sketch!"
         VerticalOptions= "Start"
         XAlign="Center"
         Rotation="15"
         IsVisible="true"
         Font="Bold, 80"
         TextColor="Red" / >

</ContentPage>";

varpage = new ContentPage {Padding = new Thickness(0,20,0,0)};
vars=((((MethodInfo)((TypeInfo)(((TypeInfo)((new AssemblyName("Xamarin.Forms.Xaml, Version=1.2.3.0, Culture=neutral, PublicKeyToken=null"))
    .GetTypes().Where(t=>t.FullName=="Xamarin.Forms.Xaml.Extensions").First())).DeclaredMembers
    .Where(t=>!((MethodInfo)t).Attributes.HasFlag(System.Reflection.MethodAttributes.Family))).First())).MakeGenericMethod(typeof(ContentPage))).Invoke(null,newobject[]{page,xaml})!=null
RootPage.Children.Add(page);

You can paste it to view the interpreted view of XAML in Xamarin Android Player or iOS Simulator.

After that, the results of editing the XAML portion will be updated immediately.

Note that " must be marked as " for the XAML description here.

Also, how it works is explained in Record of the Fifth Xamarin.Forms War (XAML Live Preview).


2022-09-30 12:06

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.