Toast -Benachrichtigungsaktion öffnet eine neue Instanz meiner Winui -App, anstatt eine bestimmte Logik auszuführenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Toast -Benachrichtigungsaktion öffnet eine neue Instanz meiner Winui -App, anstatt eine bestimmte Logik auszuführen

Post by Anonymous »

Diese App wurde mit Winui 3 < /p>
gemacht. Lassen Sie mich also ein bisschen meine App erklären. Free (
https://apps.microsoft.com/detail/9nblg ... n-us&gl=us)
Was ich versuche,
Ich versuche, ein Toast anzuzeigen. Datei
[*] Ordner öffnen

Wenn Sie auf den Ordner öffnen, sollte er den Ordner öffnen. Wenn Sie auf die Datei öffnen, sollte sie die Datei mit 3D -Viewer öffnen. />

Code: Select all

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.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post