我对statuicon有一个非常奇怪的问题。
我正在做一个简单的项目来保存并在表格中显示一些数据,我有一个主窗口(MainWindow),其中用户插入数据,然后有另一个窗口显示数据(SumList)。还有一个状态图标,我通过对Gtk.StatusIcon进行子类化创建。问题是,当我启动应用程序并显示应显示数据的窗口(一切正常)然后关闭窗口(无论如何)时,statusIcon将从面板中消失。
此外,我发现它是因为类SumList的构造函数的长度。如果我从那里删除一些行(随机顺序),则statusicon可以正常工作。
我该如何解决这种奇怪的行为?
编辑#1 我尽量不继承StatusIcon,而是声明为MainClass的静态成员,现在它可以正常工作,很奇怪。无论如何,问题是如果statusIcon未被声明为静态,它为什么不起作用?
MainClass(StatusIcon)
class MainClass : StatusIcon
{
MainWindow window;
private MainClass()
{
window = new MainWindow();
window.Show();
Stock = Gtk.Stock.Home;
PopupMenu += rightClick;
Activate += leftClick;
}
private void rightClick (object sender, Gtk.PopupMenuArgs evt){
window.Hide();
}
private void leftClick (object sender, EventArgs e){
window.Show();
}
public static void Main (string[] args)
{
Application.Init ();
new MainClass();
Application.Run ();
}
}
SumList类
public partial class SumList : Gtk.Window
{
public SumList () : base(Gtk.WindowType.Toplevel)
{
this.Build ();
// create the "title" column ------------ //
TreeViewColumn title = new TreeViewColumn();
CellRendererText titleR = new CellRendererText();
title.PackStart(titleR, true);
title.AddAttribute(titleR, "text", 0);
// create the "detial" column ----------- //
TreeViewColumn detail = new TreeViewColumn();
CellRendererText detailR = new CellRendererText();
detail.PackStart(detailR, true);
detail.AddAttribute(detailR, "text", 1);
// create the "price" column ------------ //
TreeViewColumn price = new TreeViewColumn();
CellRendererText priceR = new CellRendererText();
price.PackStart(priceR, true);
price.AddAttribute(priceR, "text", 2);
// create the "date" column ------------- //
TreeViewColumn date = new TreeViewColumn();
CellRendererText dateR = new CellRendererText();
date.PackStart(dateR, true);
date.AddAttribute(dateR, "text", 3);
// set the columns names
title.Title = "Title";
detail.Title = "Detail";
price.Title = "Price";
date.Title = "Date";
// append columns to the treeview
this.treeview.AppendColumn(title);
this.treeview.AppendColumn(detail);
this.treeview.AppendColumn(price);
this.treeview.AppendColumn(date);
// set the model
this.treeview.Model = Singleton.Model.Instance.Data;
}
}
MainWindow类
public partial class MainWindow: Gtk.Window{
public MainWindow (): base (Gtk.WindowType.Toplevel){
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a){
Application.Quit ();
a.RetVal = true;
}
protected void OnButtonOKClicked (object sender, System.EventArgs e){
SumList list = new SumList();
list.Show();
}
protected void onButtonHideClicked (object sender, System.EventArgs e){
entrySum.Text = "";
entryTitle.Text = "";
this.Hide();
}
}
答案 0 :(得分:1)
很简单,你的GTK控件正在收集垃圾。
public static void Main (string[] args)
{
Application.Init ();
new MainClass();
Application.Run ();
}
您现在不再对MainClass
实例进行任何实时引用。国际海事组织,你很幸运,该计划甚至这样做。