Monobjc :: 添加 NSStatusItem
我正在尝试从 Mono 的 Monobjc 桥中添加 NSStatusItem。 该函数被调用,并且不会引发异常,但我的图标没有出现:(。
这是我的代码:
#define DEBUG_APP
using System;
using Monobjc.Cocoa;
using Monobjc;
namespace YvanSoftware.TwitMenu
{
[ObjectiveCClass]
public class TwitMenuController : NSObject
{
[ObjectiveCField]
NSStatusItem _statusItem;
[ObjectiveCMessage("awakeFromNib")]
public void AwakeFromNib()
{
try {
if (_statusItem == null) {
NSMenu menu = new NSMenu("");
_statusItem = NSStatusBar.SystemStatusBar.StatusItemWithLength(32f);
_statusItem.Image = NSImage.ImageNamed("twitter.png");
NSMenuItem menuItem = new NSMenuItem("Send tweet!",new IntPtr(),"");
menuItem.ActionEvent += new ActionEventHandler(showTweetWindow);
menu.AddItem(menuItem);
_statusItem.Menu = menu;
DebugPrint("Status item added??");
}
} catch (Exception ex) {
DebugPrint(ex.Message);
}
}
public TwitMenuController(IntPtr i) : base(i) {}
public TwitMenuController() {}
public void showTweetWindow(Id sender) {
Console.WriteLine("Not implemented. (0x01)");
}
[ObjectiveCMessage("showAbout:")]
public void showAbout() {
Console.WriteLine("Not implemented (0x02)");
}
void DebugPrint(string s) {
#if DEBUG_APP
Console.WriteLine("*** DEBUG: " + s + " ***");
#endif
}
}
}
提前致谢,
Yvan
I'm trying to add an NSStatusItem from within the Monobjc bridge for Mono.
The function gets called, and doesn't throw an exception, but my icon doesn't appear :(.
Here 's my code:
#define DEBUG_APP
using System;
using Monobjc.Cocoa;
using Monobjc;
namespace YvanSoftware.TwitMenu
{
[ObjectiveCClass]
public class TwitMenuController : NSObject
{
[ObjectiveCField]
NSStatusItem _statusItem;
[ObjectiveCMessage("awakeFromNib")]
public void AwakeFromNib()
{
try {
if (_statusItem == null) {
NSMenu menu = new NSMenu("");
_statusItem = NSStatusBar.SystemStatusBar.StatusItemWithLength(32f);
_statusItem.Image = NSImage.ImageNamed("twitter.png");
NSMenuItem menuItem = new NSMenuItem("Send tweet!",new IntPtr(),"");
menuItem.ActionEvent += new ActionEventHandler(showTweetWindow);
menu.AddItem(menuItem);
_statusItem.Menu = menu;
DebugPrint("Status item added??");
}
} catch (Exception ex) {
DebugPrint(ex.Message);
}
}
public TwitMenuController(IntPtr i) : base(i) {}
public TwitMenuController() {}
public void showTweetWindow(Id sender) {
Console.WriteLine("Not implemented. (0x01)");
}
[ObjectiveCMessage("showAbout:")]
public void showAbout() {
Console.WriteLine("Not implemented (0x02)");
}
void DebugPrint(string s) {
#if DEBUG_APP
Console.WriteLine("*** DEBUG: " + s + " ***");
#endif
}
}
}
Thanks in advance,
Yvan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在创建后立即保留
_statusItem
变量:You have to retain the
_statusItem
variable right after its creation: