0
votes

Recently Xamarin Forms Previewer was introduced for Android and iOS Xamarin Forms applications.( https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-previewer/ )

Wanted to know how Xamarin Forms Previewer works internally. I mean how are the native controls rendered to the previewer when a change is done in the xaml file.

I could find Xamarin Forms source code from github (https://github.com/xamarin/Xamarin.Forms).

But is the source for Xamarin Forms Previewer source code open source as well so that it can be referred to better understand the working on Xamarin Forms Previewer?

Thanks

2

2 Answers

3
votes

The source for the previewer aren't in the Xamarin.Forms repository.

It works just as you expect it would:

When the IDE detects a file change, the previewer asks Xamarin.Forms to render the Page, but instead of using the XAML file bundled in the assembly (would require rebuilding), the previewer provides it's own XAML string. It does that by setting a XamlFileProvider (https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Xaml/XamlLoader.cs#L42).

When Xamarin.Forms loads a Page, it checks for that Loader and use that file instead: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Xaml/XamlLoader.cs#L138

Feel free to use this information to better understand how it works, but do not even consider building something that uses that mechanism. Those are internal APIs, and then can change without notice.

0
votes

The best way to do this is to read the source code. Unfortunately, there are no source codes for Previewer in free access(GitHub).