如何在Windows Toast Notifications中使用资源中使用位图图像
我正在尝试通过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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尚未成功使用
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?