Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open window using a controller with Xamarin Mac

I've got a status menu on a tray icon application with Xamarin Mac. There is no window shown by setting Application is agent (UIElement) to 1. A login window must only be shown after a menuItem is clicked. (which is connected using a action.)

The following code initialized a new MainWindowController after a button is clicked. This action is called because a breakpoint is hit, yet no window is shown.

partial void OpenLoginWindow(NSMenuItem sender)
{
    var loginController = new MainWindowController();
    loginController.Window.MakeKeyAndOrderFront(this);
    loginController.ShowWindow(this);
}

When I set Application is agent (UIElement) back to 0. The window gets shown when the dock icon is clicked. But when the login menu item is clicked, the window are initialized, but it is not brought to the front.

The Main nib file name in Info.plist is set to MainMenu which is not the file for the window.

like image 469
Waaghals Avatar asked Jan 08 '16 10:01

Waaghals


People also ask

How do I open Xamarin project on Mac?

In Visual Studio for Mac, right-click on the existing Xamarin. Forms solution and choose Add > Add New Project... In the New Project window choose Mac > App > Cocoa App and press Next.

Can you use Xamarin on Mac?

With Xamarin. Forms, you can use C# or XAML to build cross-platform user interfaces for iOS, Android, and macOS.

Do you need a Mac for Xamarin iOS?

The Mac is required for building as well as running the iOS simulator. You can either use it as a build server, and actually do your development in Visual Studio (either in a standalone PC, or on a VM running on your Mac), or you can do your development directly on the Mac using Xamarin Studio as your IDE.

Can I program C# on a Mac?

Visual Studio 2022 for Mac includes nearly everything you'll need for .NET 7 development, from responsive C# web UIs in Blazor to event-driven solutions using Azure Functions.


1 Answers

Looks like this always works. But because the application is set to Application is agent (UIElement) no dock item is shown and does not show when ALT+TAB'ing. Because Xamarin Studio had focus the window was started in the background.

like image 148
Waaghals Avatar answered Oct 06 '22 08:10

Waaghals