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:

  1. Open file
  2. 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.

本文标签: