1

私は statuicon で非常に奇妙な問題を抱えています。

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

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

この奇妙な動作を修正するにはどうすればよいですか?

EDIT #1 StatusIcon をサブクラス化しないようにしています代わりに、MainClass の静的メンバーとして宣言しましたが、正常に動作するようになりました。とにかく問題は、statusIcon が static と宣言されていない場合、なぜ機能しないのかということです。

メインクラス (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();
    }
}
4

1 に答える 1

1

シンプルに、GTK コントロールはガベージ コレクションを取得しています。

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

    Application.Run ();
}

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

于 2012-05-10T20:34:12.977 に答える