简体   繁体   中英

Xamarin Forms Rg.Plugins.Popup

I'm trying to make a popup page in Xamarin Forms 3.0.0.530893. I use the Rg.Plugins.Popup v.1.1.4.158-pre and test it on Android 8.0.0. But the popup is displayed in the left top corner, no matter what I put in the Horizontal and Vertical options.

Here is my Popup Page

<?xml version="1.0" encoding="utf-8" ?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ScanApp.Page.Popup.SignOutPopup"
         xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
  <StackLayout BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="Center">
    <Label Text="Log ud" TextColor="Black"></Label>
    <Label Text="AutomationProperties du sikker på du ønsker at logge ud?"></Label>
    <Button Text="LOG UD"></Button>
    <Button Text="ANNULLER"></Button>
  </StackLayout>
</pages:PopupPage>

And here is backend

using Rg.Plugins.Popup.Pages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace ScanApp.Page.Popup
{
  [XamlCompilation(XamlCompilationOptions.Compile)]
  public partial class SignOutPopup : PopupPage
  {
    public SignOutPopup ()
    {
        InitializeComponent ();
    }
}

Here I initialize the plugin for Android in MainActivity OnCreate

 Rg.Plugins.Popup.Popup.Init(this,bundle);

Here I push the page

Navigation.PushPopupAsync(new SignOutPopup());

I'm not sure on how works this plugin exactly , but I already used it in a past project and here what I did:

I suggest you to define your page like this. Embed your stacklayout into a 'fullscreen' Frame, and set some margin and paddig to your frame:

<?xml version="1.0" encoding="utf-8" ?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ScanApp.Page.Popup.SignOutPopup"
         xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
         >

    <Frame HorizontalOptions="Center" VerticalOptions="Center" 
           BackgroundColor="White" Margin="20" Padding="20">

      <StackLayout>
        <Label Text="Log ud" TextColor="Black"></Label>
        <Label Text="AutomationProperties du sikker på du ønsker at logge ud?"></Label>
        <Button Text="LOG UD"></Button>
        <Button Text="ANNULLER"></Button>
      </StackLayout>

    </Frame>
</pages:PopupPage>

Xamarin Forms Frame class has specific properties like ' CornerRadius ' or ' HasShadow ' to give a real 'popup' appearance to your Frame... And your frame should be centered.

Tell me if it's working...

The problem was not with the plugin or popup page. The problem was these lines that I put in the android MainActivity, for the app to fill the whole screen

if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
   Window.AddFlags(WindowManagerFlags.LayoutNoLimits);
   Window.AddFlags(WindowManagerFlags.LayoutInScreen);
   Window.DecorView.SetFitsSystemWindows(true);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM