2012-05-09 17 views
1

私はstatuiconに非常に奇妙な問題があります。Gtk#statusiconが消える

テーブルにデータを保存して表示するための簡単なプロジェクトでは、ユーザーがデータを挿入したMainWindow(MainWindow)と、表示されるデータ(SumList)がある別のウィンドウがあります。また、Gtk.StatusIconをサブクラス化して作成したステータスアイコンもあります。問題は、アプリケーションを起動してデータを表示するウィンドウ(すべて動作)を表示してから、ウィンドウを閉じると(状況に関係なく)statusIconがパネルから消えてしまうことです。

また、SumListクラスのコンストラクタの長さが原因であることがわかりました。そこからいくつかの行を削除すると(ランダムな順序)、statusiconは正常に動作します。

どのようにこの異常な動作を修正できますか?

EDIT#1 は、私の代わりに私がMainClassの静的メンバとして宣言しているStatusIconをサブクラス化しないようにしようと、今、それは奇妙な、それが必要として動作します。とにかく、statusIconがstatic宣言されていないと、なぜそれが動作しないのでしょうか?

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;  

    } 
} 

メイン・ウィンドウクラス

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(); 
    } 
} 

答えて

1

シンプル、あなたのGTKコントロールは、ガベージコレクションなっています。

public static void Main (string[] args) 
{ 
    Application.Init(); 
    new MainClass(); 

    Application.Run(); 
} 

MainClassインスタンスへのライブ参照がなくなりました。 IMOでは、このプログラムでさえ幸運です。

+0

私はこれを試しました MainClass main = new MainClass(); しかし、それは同じことをします、どのように動作するかは、statusiconが静的であるかどうかだけです – Jan