Xamarin.forms:(Rg.Plugins.Popup)Nuget包的使用小案例

本文介绍了如何在Xamarin.Forms项目中使用Rg.Plugins.Popup NuGet包,通过创建一个可移植类库(PCL)项目,并在各个项目中安装该包,实现弹出窗口功能。文章提供了详细的步骤,包括新建项目、添加NuGet包以及展示运行效果。同时,展示了App.cs、MainPage.xaml、MyDialogPage.xaml的相关代码段。
摘要由CSDN通过智能技术生成

操作步骤:
首先:文件》新建》项目》已安装》Visual C#》Cross-Plaform
出现以下界面选择第一项
这里写图片描述
确定》选择模板》空白应用》可移植类库(PCL)
这里写图片描述
OK
右键》可移植的(PCL)》管理NuGet程序包
查找Rg.Plugins.Popup包并下载
这里写图片描述
每个项目都装上以免出现问题
这里写图片描述
这里写图片描述
运行效果图:
这里写图片描述
这里写图片描述
DCL:
App.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyDialog.Pages;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace MyDialog
{
    public class App : Application
    {
        public App()
        {
            // The root page of your application
            MainPage = new NavigationPage(new MainPage())
            {
                BarBackgroundColor = Color.FromHex("#7dbbe6"),
                BarTextColor = Color.White
            };
        }
        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

MainPage.xaml
XMAL部分:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyDialog.Pages.MainPage">
    <ContentPage.Resources>
        <ResourceDictionary>
            <Style TargetType="Button">
                <Setter Property="BackgroundColor" Value="#7dbbe6"/>
                <Setter Property="TextColor" Value="White"/>
            </Style>
        </ResourceDictionary>
    </ContentPage.Resources>
    <StackLayout Spacing="20" Margin="10, 15">
        <Button Text="My Dialog" Clicked="OnOpenDialogPage"></Button>
    </StackLayout>
</ContentPage>

C#部分:

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

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

namespace MyDialog.Pages
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值