gpt4 book ai didi

wpf - 在 WPF 应用程序中启动 Toastnotification

转载 作者:行者123 更新时间:2023-12-04 14:25:52 25 4
gpt4 key购买 nike

我用 C#(使用 Visual Studio Community 2015)创建了一个 WpfApplication,我想发送一些 Windows 10 通知。我认为我应该使用“ToastContent”然后将其添加到“ToastNotification”中,...

我添加了“Microsoft.Toolkit.Uwp.Notification”,但无法添加“Microsoft.Toolkit.Uwp.UI”(我认为需要显示通知)。它说 :

Could not install package 'Microsoft.Toolkit.Uwp 1.2.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework.



我该怎么做才能安装这个包?或者是否有另一种解决方案来启动 Windows 10 通知?

谢谢 :)

最佳答案

好的,经过几个小时的搜索,这有点容易......

第 1 步:卸载项目,然后将此元素添加到第一个属性组:<targetplatformversion>10.0</targetplatformversion>
第 2 步:重新加载项目

第 3 步:添加对您的项目的引用“Windows > Core > Windows.Data & Windows.UI”

第四步 :

string xml = $@"
<toast>
<visual>
<binding template='ToastGeneric'>
<text>Some title</text>
<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</text>
</binding>
</visual>
</toast>";

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

var toast = new ToastNotification(doc);

ToastNotificationManager.CreateToastNotifier("ToastDesktop").Show(toast);

享受 :) !

关于wpf - 在 WPF 应用程序中启动 Toastnotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41360958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com