Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How do I show a form sheet using an custom iOS renderer?

$
0
0

Hi,

This has been asked before, but I couldn't find a good match for my needs!
I am using the latest version of Xamarin Forms (1.4.0) and am trying to display a modal page as a FormSheet style on iOS for iPad, e.g: http://i.stack.imgur.com/XUnGi.png
Here’s what i’m currently doing:

1. Have a Xamarin.Forms ContentPage base class:

namespace formsheet.Views.Common
{
    using Xamarin.Forms;

    /// <summary>The modal form sheet content page.</summary>
    public class ModalFormSheetContentPage : ContentPage
    {
    }
}

2. I have a custom renderer that sets the modal presentation style to FormSheet:

    using Xamarin.Forms;
    [assembly: ExportRenderer(typeof(ModalFormSheetContentPage), typeof(ModalFormSheetRenderer))]
    namespace formsheet.iOS.Renderers
    {
        using System;

        using UIKit;

        using Xamarin.Forms.Platform.iOS;

        /// <summary>The modal form sheet renderer.</summary>
        public class ModalFormSheetRenderer : PageRenderer
        {
            public ModalFormSheetRenderer()
            {
                this.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
            }
        }
    }

3. Any views that I create inherit the ModalFormSheetContentPage:

    <?xml version="1.0" encoding="utf-8" ?>
    <common:ModalFormSheetContentPage
                 xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:common="clr-namespace:formsheet.Views.Common;assembly=formsheet"
                 x:Class=“formsheet.Views.AddPersonModalPage.AddPerson">
      <Label Text="Modal Test" VerticalOptions="Center" HorizontalOptions="Center" />
      <Button Text="Back" Command="{Binding BackCommand}"></Button>
    </common:ModalFormSheetContentPage>

4. I call the AddPerson xaml using PushModalAsync on a navigation page:

await this.RootNavigation.Navigation.PushModalAsync((Page)new AddPerson());

In theory this makes it easy for me to create many custom modal pages. Unfortunately, the modal page is always fullscreen even though the renderer constructor is called. I have also tried removing the base class and putting the renderer on the AddPerson content page directly, but same issue.

Is there a way to achieve this?
Also, is there an equivalent of the FormSheet for Android?

Hope this scenario makes sense.

Thanks


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>