Use the Surface Duo SDK with Xamarin

The Surface Duo SDK for Xamarin apps is available from NuGet. Add the correct NuGet for your project type using the instructions below.

Xamarin.Forms

Follow these steps to add the Surface Duo SDK to a Xamarin.Forms project:

  1. Open the NuGet Package Manager dialog for your project.

  2. Under the Browse tab, search for Xamarin.Forms.DualScreen.

  3. Install the Xamarin.Forms.DualScreen package into your project.

  4. Add the the following initialization method call to the Android project's MainActivity class, in the OnCreate event:

    Xamarin.Forms.DualScreen.DualScreenService.Init(this);
    

    This method is required for the app to be able to detect changes in the app's state, such as being spanned across two screens.

  5. Update the Activity attribute on the Android project's MainActivity class, so that it includes all these ConfigurationChanges options:

    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.UiMode
    

    These values are required so that configuration changes and span state can be more reliably reported.

The APIs from the Surface Duo SDK for Xamarin.Forms will be available in the Xamarin.Forms.DualScreen namespace. The Xamarin.Forms SDK consists of two parts:

Xamarin.Android

Follow these steps to add the Surface Duo SDK to a Xamarin.Android project:

  1. Open the NuGet Package Manager dialog for your project.
  2. Under the Browse tab, search for Xamarin.DuoSdk.
  3. Install the Xamarin.DuoSdk package into your project.

You can review the Microsoft dual-screen SDK reference. The APIs from the Surface Duo SDK for Xamarin are available in the Microsoft.Device.Display namespace.

Samples

Visit the Xamarin samples to see examples of the SDK for both Xamarin.Forms and Xamarin.Android.