【问题标题】:Xamarin Forms Rg.Plugins.PopupXamarin Forms Rg.Plugins.Popup
【发布时间】:2018-06-08 15:58:24
【问题描述】:

我正在尝试在 Xamarin Forms 3.0.0.530893 中创建一个弹出页面。我使用 Rg.Plugins.Popup v.1.1.4.158-pre 并在 Android 8.0.0 上对其进行测试。但是无论我在“水平”和“垂直”选项中放置什么,弹出窗口都会显示在左上角。

这是我的弹出页面

<?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>

这里是后端

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

这里我在MainActivity OnCreate中为Android初始化插件

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

我这里推送页面

Navigation.PushPopupAsync(new SignOutPopup());

【问题讨论】:

    标签: c# xamarin popup


    【解决方案1】:

    我不确定这个插件到底是如何工作的,但我已经在过去的项目中使用过它,这里我做了什么:

    我建议你这样定义你的页面。将您的 stacklayout 嵌入到“全屏”框架中,并为您的框架设置一些边距和 paddig:

    <?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 类 具有特定属性,例如“CornerRadius”或“HasShadow”,可为您的 Frame 提供真正的“弹出”外观...并且您的框架应该居中。

    告诉我它是否有效...

    【讨论】:

    • 问题依然存在。通过设置与打开弹出窗口的页面上的图片相同大小的边距,我已经能够使其居中。
    【解决方案2】:

    问题不在于插件或弹出页面。问题是我放在 android MainActivity 中的这些行,以便应用程序填满整个屏幕

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-04
      • 2017-01-05
      • 2019-11-25
      • 1970-01-01
      • 2014-09-13
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多