2

我需要在 Xamarin.Forms 上使用 toasts。我找到了 Toasts.Forms.Plugin但它不适用于 WP8.1

我在 WinPhone8 上遇到了很多性能问题,所以我创建了 WP8.1 项目。

我需要做什么才能使其在 WP8.1 上运行?有人可以帮我弄清楚我需要做的改变吗?

编辑:Toasts.Forms.Plugin添加包时出现以下错误

install-package : Could not install package 'Toasts.Forms.Plugin 1.0.6.18'. You are trying to install this package into a project that 
targets 'WindowsPhoneApp,Version=v8.1', but the package does not contain any assembly references or content files that are compatible with 
that framework. For more information, contact the package author.
At line:1 char:1
+ install-package Toasts.Forms.Plugin
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
4

2 回答 2

1

如果您使用可移植项目,Toasts.Forms.Plugin 实际上可用于 WP8.1。我在我的一个带有 WP8.1 的 Xamarin Forms 项目中使用它

只需使用包管理器控制台安装包,并确保选择 WP8.1 项目作为“默认项目”:

install-package Toasts.Forms.Plugin

它应该会在您的 WP8.1 项目中的 packages.config 中添加类似于以下元素的内容。

<package id="Toasts.Forms.Plugin" version="1.0.6.18" targetFramework="wp81" />

要使其与其他 Toasts.Forms.Plugins 一起使用,您可以像这样使用 DependencyService:

DependencyService.Get<IToastNotificator>()

如果遇到问题,您可以使用共享库,并让每个平台注入它自己的依赖项,例如:

public class ServiceRepositoryBase
{
    protected static IToastNotificator ToastNotificator;
    public static void Init(IToastNotificator toastNotificator)
    {
        ToastNotificator = toastNotificator;
    }
    // Other code here...
}

在您的 MainPage.xaml.cs 中:

ServiceRepositoryBase.Init(DependencyService.Get<IToastNotificator>());
于 2015-09-04T06:12:43.543 回答
0

那是因为该插件目前仅提供 WinPhone Silverlight (wp8) 的库。您可能正在为您的项目使用 WinRT (wpa81),并且插件中没有针对此目标的特定库。要使用它,您唯一能做的就是将您的 WinPhone 项目更改为 Silverlight 8.1 项目。

可以从 .nupkg 文件中找出支持的目标 https://github.com/EgorBo/Toasts.Forms.Plugin/blob/master/.nuget/Toasts.Forms.Plugin.1.0.6.18.nupkg

于 2015-09-04T10:41:27.443 回答