问题描述
我想将Rg.Plugins.Popup用于Xamarin.Forms,但是不幸的是我无法将PopupPage添加到项目中.我正在使用VIsual Studio2017.在AddNewItem
窗口中根本没有PopupPage.
I would like to use Rg.Plugins.Popup for Xamarin.Forms but unfortunately I cannot add PopupPage to the project. I am using VIsual Studio 2017. In AddNewItem
window there is no PopupPage at all.
我尝试这样添加ContentPage
:
public partial class CustomPopupPage : ContentPage
{
public CustomPopupPage ()
{
InitializeComponent ();
}
}
但是每当我尝试将类型ContentPage
更改为PopupPage
时,都会出现以下错误:Partial declarations of 'CustomPopupPage' must not specify different base classes.
but whenever i try to change type ContentPage
to PopupPage
I get following error: Partial declarations of 'CustomPopupPage' must not specify different base classes.
问题在于第二部分类在自动生成的文件CustomPopupPage.xaml.g.cs
中,并且我无法修改该文件,因为每次应用程序在编译时都会重写该文件.
The problem is that second partial class is in auto-generated file CustomPopupPage.xaml.g.cs
and I cannot modify that file because each time application is compiling it rewrites that file.
我想我在这里缺少明显的东西,因为演示工作正常.
I think I am missing something obvious here because demo is working fine.
推荐答案
PopupPage
是ContentPage的子类.因此,您必须添加一个新的ContentPage
并更改xaml和代码beindd中的超类.
PopupPage
is a subclass of ContentPage .So you have to add a new ContentPage
and change the superclass both in xaml and code benind .
首先,从共享项目和特定平台(iOS和Android)中的nuget安装软件包 Rg.Plugins.Popup .
Firstly , install the package Rg.Plugins.Popup from nuget in share project and specific platform (iOS and Android).
插件需要初始化.要在应用程序内部使用PopupPage,每个平台应用程序必须初始化Rg.Plugins.Popup.初始化步骤因平台而异,将在以下各节中讨论.
The plugin requires to be initialized. To use a PopupPage inside an application, each platform application must initialize the Rg.Plugins.Popup. This initialization step varies from platform to platform and is discussed in the following sections.
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Rg.Plugins.Popup.Popup.Init();
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
return base.FinishedLaunching (app, options);
}
Android-> MainActivity
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Rg.Plugins.Popup.Popup.Init(this, bundle);
Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication (new App ());
}
xaml
<?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"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
x:Class="MyProject.MyPopupPage">
<!--You can set an animation in the xaml file or in the csharp code behind-->
<pages:PopupPage.Animation>
<animations:ScaleAnimation
PositionIn="Center"
PositionOut="Center"
ScaleIn="1.2"
ScaleOut="0.8"
DurationIn="400"
DurationOut="300"
EasingIn="SinOut"
EasingOut="SinIn"
HasBackgroundAnimation="True"/>
</pages:PopupPage.Animation>
<!--You can use any elements here which are extended from Xamarin.Forms.View-->
<StackLayout
VerticalOptions="Center"
HorizontalOptions="Center"
Padding="20, 20, 20, 20">
<Label
Text="Test"/>
</StackLayout>
</pages:PopupPage>
在后面的代码中
public partial class MyPopupPage : Rg.Plugins.Popup.Pages.PopupPage
{
public MyPopupPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
}
}
更新
似乎是vs 2017的现有问题,在VS 2019上运行良好.我将把这个问题发布给产品团队.
Update
It seems an existing issue of vs 2017 , on VS 2019 it works fine . And I will post this issue to product teams .
这篇关于无法将PopupPage添加到Visual Studio中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!