This sample shows a shared Xamarin.Forms UI being embedded into non-Xamarin.Forms iOS, Android and UWP applications. With this method developers can use as much or as little Xamarin.Forms in their application as desired.
The HistoryPage.xaml demonstrates using an image and custom fonts across native applications.
Xamarin.Forms services such as DependencyService and MessagingCenter work with the exception of Navigation. Binding also works when setting the context.
NOTE: This is an early preview and not all features have been evaluated.
This is very early and not merged into Xamarin.Forms master. To get the package, add this feed to your NuGet sources:
- Add the source:
https://www.myget.org/F/xamarinforms-dev/api/v3/index.json
- Check Pre-Release
- Select and install the package with the feature name "Embedding".
3.0.0.100-embeddingpreview
Watch the presentation and view the slides on Channel 9.
public void ShowHistory()
{
if (_history == null)
{
// #1 Initialize Forms.Init(Context, Bundle)
Forms.Init(this, null);
// #2 Use it with CreateFragment(Context)
_history = new HistoryPage().CreateFragment(this);
}
// And push that fragment onto the stack
FragmentTransaction ft = FragmentManager.BeginTransaction();
ft.AddToBackStack(null);
ft.Replace(Resource.Id.fragment_frame_layout, _history, "history");
ft.Commit();
}
Call Forms.Init()
before creating the UIViewController.
public void ShowHistory()
{
if (_history == null)
{
// #2 Use it
_history = new HistoryPage().CreateViewController();
}
// And push it onto the navigation stack
_navigation.PushViewController(_history, true);
}
In this demo we placed the History Page inside a flyOut Frame. Call Forms.Init(e)
prior.
var x = new HistoryPage().CreateFrameworkElement();