操作步骤:
首先:文件》新建》项目》已安装》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)]