首页 > 解决方案 > 如何在 Xamarin.Forms 中进行通知

问题描述

如何使用 XAML 或 C# 代码在 Xamarin.Forms 中发出通知?

我可以在带有 Xamarin.Forms 的 Ios 中使用它吗?

标签: c#.netxamarinxamarin.forms

解决方案


看看精彩的Toasts.Forms.Plugin

您可以简单地触发这样的通知

var notificator = DependencyService.Get<IToastNotificator>();

var options = new NotificationOptions()
        {
            Title = "Title",
            Description = "Description"
        };
await notificator.Notify(options);

如果用户单击、关闭等通知,您可以事件做出反应

var result = await notificator.Notify(options);

// result is a NotificationResult with a NotificationAction in it
public enum NotificationAction
{
    Timeout = 1, // Hides by itself
    Clicked = 2, // User clicked on notification
    Dismissed = 4, // User manually dismissed notification
    ApplicationHidden = 8, // Application went to background
    Failed = 16 // When failed to display the toast
} 

对于 android,您可以在样式SnackbarNotification样式之间进行选择。查看文档以获得控制权以根据需要执行通知!


推荐阅读