BB1*_*BB1 3 c# cocoa monomac xamarin.mac
我试图在MonoMac/Xamarin.Mac中创建一个没有停靠图标的应用程序,在启动时也没有可见窗口,并且在右上方的菜单栏中只有一个图标.
我在Info.plist中设置了LSUIElement = 1(尝试了String和Boolean类型),但在应用程序启动时根本不显示状态菜单图标.我可以让它出现的唯一方法是删除LSUIElement标志,尽管Dock图标变得可见.
我使用的代码片段是:
public partial class AppDelegate : NSApplicationDelegate
{
public AppDelegate ()
{
}
public override void FinishedLaunching (NSObject notification)
{
// Construct menu that will be displayed when tray icon is clicked
var notifyMenu = new NSMenu();
var exitMenuItem = new NSMenuItem("Quit",
(a,b) => { System.Environment.Exit(0); }); // Just add 'Quit' command
notifyMenu.AddItem(exitMenuItem);
// Display tray icon in upper-right-hand corner of the screen
var sItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
sItem.Menu = notifyMenu;
sItem.Image = NSImage.FromStream(System.IO.File.OpenRead(
NSBundle.MainBundle.ResourcePath + @"/menu_connected.png"));
sItem.HighlightMode = true;
// Remove the system tray icon from upper-right hand corner of the screen
// (works without adjusting the LSUIElement setting in Info.plist)
NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Accessory;
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人知道在MonoMac中创建一个没有停靠图标且只有菜单栏图标的无窗口应用程序的好方法?
谢谢,
BB
尝试为"主nib文件名"指定.xib
我之前做过这个,它对我来说很好.像这样的东西:
在C#中创建了一个'AppController'类:
[Register("AppController")]
public partial class AppController : NSObject
{
public AppController()
{
}
public override void AwakeFromNib()
{
var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
statusItem.Menu = statusMenu;
statusItem.Image = NSImage.ImageNamed("f3bfd_Untitled-thumb");
statusItem.HighlightMode = true;
}
Run Code Online (Sandbox Code Playgroud)在MainMenu.xib中,我删除了应用程序菜单
AppControllerAppController带有插座的地方尝试使用.xib.如果它不起作用,也许我可以分享我的项目让你分开.