4

davidortinau/build2017-new-in-xamarin-forms

 3 years ago
source link: https://github.com/davidortinau/build2017-new-in-xamarin-forms
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Microsoft Build 2017 - Weather Sample - Xamarin.Forms Embedding (PREVIEW)

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.

Get the 3.0-preview NuGet

This is very early and not merged into Xamarin.Forms master. To get the package, add this feed to your NuGet sources:

Watch the presentation and view the slides on Channel 9.

Android

embedding-android.gif
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();
}
embedding-ios.gif

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);
}

UWP Desktop

embedding-uwp-desktop.gif

In this demo we placed the History Page inside a flyOut Frame. Call Forms.Init(e) prior.

var x = new HistoryPage().CreateFrameworkElement();

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK