无法将PopupPage添加到Visual Studio中的项目

编程入门 行业动态 更新时间:2024-10-17 11:34:38
本文介绍了无法将PopupPage添加到Visual Studio中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将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="xamarin/schemas/2014/forms" xmlns:x="schemas.microsoft/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中的项目

本文发布于:2023-11-11 05:46:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577549.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   PopupPage   Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!