WPF通知设置

huangapple go评论73阅读模式
英文:

WPF Notification Settings

问题

我正在开发一个WPF项目,想要为应用程序创建一个通知机制。具体来说,用户可以转到“设置”选项卡,更改通知的设置(例如每天上午7点或每周星期四下午2点等)。一旦设置好了,他们将在桌面屏幕的右下角看到一个弹出式通知。我知道我需要一个API来实现这个功能。当通知设置的时间到达并且通知显示时,将调用API。我已经对System.Threading.TimerQuartz.NET进行了研究,但没有找到与WPF通知相关的信息。有没有人知道有关如何实现定时器和通知的信息来源,我可以参考?我会非常感激任何帮助。谢谢。

修改后的问题:
只是为了澄清我的问题,我想知道如何开发逻辑,以便在特定的日期/时间(取决于用户的设置)调用API来获取通知数据,然后将结果显示为弹出式通知。
因此,主要问题是如何定期调用API,即使应用程序没有打开和运行。

英文:

I am working on a WPF project and I want to create a notification mechanism for the app. Specifically, the user can go to Settings tab, change the settings for the notifications (ex. daily at 7am or weekly every Thursday 2PM, etc.). Once the settings is set, they will see a toast notification popping up in the bottom right corner of the desktop screen. I am aware that I will need an API for this. The API is called when the notification set time comes and the notification is shown. I have been doing research about System.Threading.Timer and Quartz.NET but I didn't find anything related to WPF notification. Does anyone know any source explaining how to implement the timer and notifications that I can refer to? I'd appreciate any help. Thank you.

Modified question:
Just to clarify my question, what I wanted to know is how can I develop the logic so that API call is made to get notification data on a specific date/time (depending on which settings users made) and then show the result as a toast.
So, the main question is how to call API periodically even when the app is not open and running.

答案1

得分: 1

你可以在你的项目中包含System.Windows.Forms类,并使用NotifyIcon。下面是为您准备的一个小示例。

var notifyIcon = new NotifyIcon();
notifyIcon.Icon = new Icon("Icon.ico");
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(5000, "标题", "消息", ToolTipIcon.Info);

如果你想在应用程序内部进行通知,而不是系统通知,我可以推荐Notification.Wpf

管理通知是一个不同的问题。这取决于你的要求和你当前的系统。应用程序会一直保持开启吗?还是会在应用程序安装期间管理一个你编写的服务?这可以根据很多问题而变化。

英文:

You can include System.Windows.Forms class in your project and use NotifyIcon. Here I have prepared a small example for you below.

var notifyIcon = new NotifyIcon();
notifyIcon.Icon = new Icon("Icon.ico");
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(5000, "Title", "Message", ToolTipIcon.Info);

If you want to make notification within the application, not the system notification, I can recommend Notification.Wpf.

Management of notifications is a different matter. It depends on your requirements and your current system. Will the app always be open? Or will it manage a service you wrote during application installation? It can vary depending on a lot of questions.

答案2

得分: 0

你可以使用操作系统的标准 toast 通知轻松完成此操作,使用 CommunityToolkit.WinUI.Notifications

假设你想在今天晚上 21:00 发送一个 toast 通知。

var time = new DateTimeOffset(DateTime.Today.AddHours(21));

new ToastContentBuilder()
    .AddText("时间提醒")
    .AddText("这是一条预定消息。")
    .Schedule(time);

就是这样。查看 计划 toast 通知

英文:

You can accomplish it easily with the OS's standard toast notification using CommunityToolkit.WinUI.Notifications.

Let's say you want to send a toast notification at 21:00pm today.

var time = new DateTimeOffset(DateTime.Today.AddHours(21));

new ToastContentBuilder()
    .AddText("TIME REMINDER")
    .AddText("This is a scheduled message.")
    .Schedule(time);

That's it. See Schedule a toast notification.

huangapple
  • 本文由 发表于 2023年7月14日 05:17:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683291.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定