无法将 PopupPage 添加到 Visual Studio 中的项目
Unable to add PopupPage to project in Visual Studio
我想将 Rg.Plugins.Popup 用于 Xamarin.Forms,但遗憾的是我无法将 PopupPage 添加到项目中。我正在使用 VIsual Studio 2017。在 AddNewItem
window 中根本没有 PopupPage。
我试着添加 ContentPage
而不是像这样:
public partial class CustomPopupPage : ContentPage
{
public CustomPopupPage ()
{
InitializeComponent ();
}
}
但是每当我尝试将类型 ContentPage
更改为 PopupPage
时,我都会收到以下错误:Partial declarations of 'CustomPopupPage' must not specify different base classes.
问题是第二部分 class 在自动生成的文件 CustomPopupPage.xaml.g.cs
中,我无法修改该文件,因为每次编译应用程序时它都会重写该文件。
我想我在这里遗漏了一些明显的东西,因为演示运行良好。
PopupPage
是 ContentPage 的子类。因此您必须添加一个新的 ContentPage
并在 xaml 和代码 benind 中更改超类。
首先,在共享项目和特定平台(iOS 和 Android)中从 nuget 安装包 Rg.Plugins.Popup。
插件需要初始化。要在应用程序内部使用 PopupPage,每个平台应用程序都必须初始化 Rg.Plugins.Popup。此初始化步骤因平台而异,将在以下部分中讨论。
iOS ->AppDelegate.cs
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 上它工作正常。我会 post 将这个问题提交给产品团队。
我想将 Rg.Plugins.Popup 用于 Xamarin.Forms,但遗憾的是我无法将 PopupPage 添加到项目中。我正在使用 VIsual Studio 2017。在 AddNewItem
window 中根本没有 PopupPage。
我试着添加 ContentPage
而不是像这样:
public partial class CustomPopupPage : ContentPage
{
public CustomPopupPage ()
{
InitializeComponent ();
}
}
但是每当我尝试将类型 ContentPage
更改为 PopupPage
时,我都会收到以下错误:Partial declarations of 'CustomPopupPage' must not specify different base classes.
问题是第二部分 class 在自动生成的文件 CustomPopupPage.xaml.g.cs
中,我无法修改该文件,因为每次编译应用程序时它都会重写该文件。
我想我在这里遗漏了一些明显的东西,因为演示运行良好。
PopupPage
是 ContentPage 的子类。因此您必须添加一个新的 ContentPage
并在 xaml 和代码 benind 中更改超类。
首先,在共享项目和特定平台(iOS 和 Android)中从 nuget 安装包 Rg.Plugins.Popup。
插件需要初始化。要在应用程序内部使用 PopupPage,每个平台应用程序都必须初始化 Rg.Plugins.Popup。此初始化步骤因平台而异,将在以下部分中讨论。
iOS ->AppDelegate.cs
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 上它工作正常。我会 post 将这个问题提交给产品团队。