我创建了一个新指标:
indicator =
new ApplicationIndicator (
"sample-application", //id of the the indicator icon
"app-icon", //file name of the icon (will look for app-icon.png)
Category.ApplicationStatus,
ExecutableFolder //the folder where to look for app-icon.png
);
//Build Popup Menu for ApplicationIndicator
Menu popupMenu = new Menu ();
indicator.Label = "init label";
...
从计时器回调函数中我想要更新指标的标签:
indicator.label = "new label";
新的标签值未应用于指示器。它仍显示字符串init label
。
答案1
我认为这只是打字错误,应该是
indicator.Label = "new label";
大写的L
。下面是我的完整工作展示(在 Ubuntu 14.04 上测试):
indicator_demo.cs
using Gtk; using AppIndicator; public class IndicatorExample { static Window win; static ApplicationIndicator indicator; static int c; public static void Main () { Application.Init (); win = new Window ("Test"); win.Resize (200, 200); Label label = new Label (); label.Text = "Hello, world!"; win.Add (label); indicator = new ApplicationIndicator ("my-id", "my-name", Category.ApplicationStatus); indicator.Status = Status.Attention; Menu menu = new Menu (); //menu.Append (new MenuItem ("Foo")); //menu.Append (new MenuItem ("Bar")); indicator.Menu = menu; indicator.Menu.Show(); indicator.Label = "init label"; win.ShowAll (); indicator.Label = "label2"; c = 0; GLib.Timeout.Add (1000, new GLib.TimeoutHandler (update)); Application.Run (); } public static bool update() { c+=1; indicator.Label = c.ToString(); return true; } }
这是一个模型Ubuntu Wiki:应用程序指示器C# 示例。
编译运行测试:
dmcs -pkg:gtk-sharp-2.0 -pkg:appindicator-sharp-0.1 indicator_demo.cs mono indicator_demo.exe