如何在Windows Toast Notifications中使用资源中使用位图图像

发布于 2025-01-31 02:48:06 字数 736 浏览 3 评论 0原文

我正在尝试通过Windows 10吐司通知构建一个未包装的WPF应用程序。我想制作pallogooverride从我的应用程序的Resources类获取资源。到目前为止,我已经尝试这样做:

public void ShowToast() {
  var toast = new ToastContentBuilder()
    .AddText("Foo!")
    .AddText("Bar.")
    .AddAppLogoOverride(new Uri("pack://application:,,,/Resources/foobar.png"), ToastGenericAppLogoCrop.Circle)
    .SetToastScenario(ToastScenario).Reminder);
  ToastNoticiationManagerCompat.CreateToastNotifier().Show(toast);
}

这样做时,通知只是说通用的“新通知”文本。因此,我尝试评论说AddappLogoOverride的部分,然后开始工作。因此,我不确定如何从Resources获得图像。

我还想提到,我没有办法使用ms-appdata://或其他人,我不确定该怎么做,我真的不知道想要将文件本地写入磁盘。

I am trying to build an unpackaged WPF app with Windows 10 Toast Notifications. I would like to make an AppLogoOverride to get a resource from the Resources class of my application. I have tried to do this so far:

public void ShowToast() {
  var toast = new ToastContentBuilder()
    .AddText("Foo!")
    .AddText("Bar.")
    .AddAppLogoOverride(new Uri("pack://application:,,,/Resources/foobar.png"), ToastGenericAppLogoCrop.Circle)
    .SetToastScenario(ToastScenario).Reminder);
  ToastNoticiationManagerCompat.CreateToastNotifier().Show(toast);
}

When doing so, the notification just says the generic "New Notification" text. So I tried commenting out the part that says AddAppLogoOverride, and it started to work. So I am not sure how to get the image from Resources.

I would also like to mention that there is no way for me to use something like ms-appdata:// or others, I am not sure how to go about doing this, and I really don't want to write the file locally to the disk.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2025-02-07 02:48:06

我尚未成功使用pack:// application:,, ,,语法到目前为止,我还没有成功将图像包括在吐司中。我猜该语法不受Toast Notification的支持,因为它是WinRT的一部分,而UWP的语法引用资源的语法与WPF的资源不同。

解决方法是,您可能不喜欢它,是在local(在应用程序的安装文件夹或其他地方的安装文件夹中)复制图像,并指定其绝对路径。请参阅我如何在C#Windows应用程序中使用自定义映像和OnClick函数进行通知?

I have not succeeded to include an image into a toast using pack://application:,,, syntax so far. I guess this syntax is not supported by toast notification because it is a part of WinRT and the syntax of UWP to refer resources is different from that of WPF.

The workaround is, you might dislike it, to copy the image in local (in the installation folder of the app or somewhere else) and specify its absolute path. See How can I make a notification in a C# Windows app with a custom image and onclick function?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文