我正在尝试显示一个简单的 toast,它显示了我部署的应用程序的第一个,但它不再显示了。我没有对部署之间的代码进行任何更改。这是基本的空白项目,除了 Mainpage 这是唯一的代码
public MainPage()
{
this.InitializeComponent();
}
public static void Notification(string title, string content)
{
// Construct the visuals of the toast
ToastVisual visual = new ToastVisual()
{
TitleText = new ToastText()
{
Text = title
},
BodyTextLine1 = new ToastText()
{
Text = content,
},
};
ToastContent toastContent = new ToastContent()
{
Visual = visual,
};
// And create the toast notification
Windows.Data.Xml.Dom.XmlDocument doc = toastContent.GetXml();
var toast = new ToastNotification(toastContent.GetXml());
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
private void buttonShowToast_Tapped(object sender, TappedRoutedEventArgs e)
{
Notification("a", "b");
}
安装的 NuGet 包: NotificationExtensions.Win10(版本:14332.0.2)
这很简单,为什么它不起作用?我是否缺少某种许可?
最佳答案
我想通了。出于某种原因,Windows 10 禁用了所有使用 Visual Studio 部署的应用程序的通知。转到设备设置中的“通知和操作”,在“从这些发件人那里获取通知”下关闭了权限。
将应用程序的权限切换为“打开”解决了这个问题。
关于c# - Toast 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41794561/