admin管理员组文章数量:1390728
This app was made using WinUI 3
So let me explain a bit my app.
My application name is NanoFlow
My app is converting lines, into STL file
Windows 11 doesn't have the ability to pent these kinds of files, but Microsoft store has a 3D viewer app, which you can download or free (
;gl=US)
What I am trying to do
I am trying to display a toast, where I have 2 buttons:
- Open file
- Open folder
When you click on open folder, it should open the folder, and when you click on open file, it should open the file using 3D viewer, I you don't have it installed, download it, indicating a progress dialog, and open the file
I already implemented a NotificationHelper
namespace NanoFlow.Helpers;
public class NotificationHelper {
public void LaunchToastNotification(string filename, string filepath) {
ToastNotificationManagerCompat.OnActivated +=
toastArgs => {
ToastArguments arguments = ToastArguments.Parse(
toastArgs.Argument);
if(arguments.TryGetValue("action", out string action)) {
HandleToastButtonAction(action, filename);
}
// Handle the toast button action
HandleToastButtonAction(action, filename);
};
Toast(filename, filepath);
}
private void HandleToastButtonAction(string action, string filename) {
switch(action) {
case "openFile":
break;
case
"openFolder":
OpenFolder(Path.GetFullPath(filename));
break;
default:
break;
}
}
private void OpenFolder(string path) {
if(!Directory.Exists(path)) {
return;
}
Process.Start("explorer.exe", $"/select,\"{path}\"");
}
// Display the toast notification
private static void Toast(string fileName, string filepath) {
new ToastContentBuilder()
.AddText("Success")
.AddText($"'{fileName}' saved successfully.")
.AddButton(new ToastButton()
.SetContent("Open File")
.AddArgument("action", "openFile")
.AddArgument("fileName", fileName)).
AddButton(new ToastButton()
.SetContent("Open Folder")
.AddArgument("action", "openFolder")
.AddArgument("filepath", filepath))
.Show();
}
}
this class will supposedly, open the folder
I am using it when I save in my main view model
but when I try to save, I get errors
Failed to register notification activator
Your app manifest must have a toastNotificationActivation extension with a valid ToastActivatorCLSID specified.
本文标签:
版权声明:本文标题:c# - Toast Notification Action Opens a New Instance of My WinUI App Instead of Executing Specific Logic - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744584149a2614097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论