如何以编程方式将 Xamarin MAC 应用程序带到前台?

How to bring Xamrin MAC app to foreground programmatically?

如何通过单击本地通知以编程方式将 Xamarin MAC 应用带到前台?我怎样才能实现它?我已经为本地通知编写了以下代码。单击该本地通知后,我想将我的应用置于前台。

NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;

    NSUserNotification notification = new NSUserNotification();
    notification.Title = title;
    notification.Subtitle = content;
    notification.InformativeText = "TEST";
    notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName;
    notification.DeliveryDate = NSDate.FromTimeIntervalSinceNow(1);  

    center.ScheduleNotification(notification);

    center.DidDeliverNotification += (s, e) =>
    {
        Console.WriteLine("Notification Delivered");              
    };

    center.DidActivateNotification += (s, e) =>
    {
        Console.WriteLine("Notification Touched");                
    };

提前谢谢你, 维维克

您可以使用NSWorkspace.SharedWorkspace.LaunchApp来"launch"您的应用,应用是否已经运行并不重要,您可以使用NSWorkspaceLaunchOptions.HideOthers来带来仅转发该应用程序的最后一个活动 window。

center.DidActivateNotification += (s, e) =>
{
    Console.WriteLine("Notification Touched");
    NSWorkspace.SharedWorkspace.LaunchApp(NSBundle.MainBundle.BundleIdentifier, NSWorkspaceLaunchOptions.HideOthers, new NSAppleEventDescriptor(), IntPtr.Zero);
};