试图以单声道制作表格

时间:2015-09-30 16:04:35

标签: mono

我刚刚开始使用monodevelop,我很难设计表单。我已经理解了容器内部小部件的概念。我想要一个滚动视图内的表。表应该有3列,我应该能够设置列名。

我已经看过mono开发的一些文档,它们展示了如何使用Node View来做同样的事情,但我还没有弄清楚它为什么会出现在一个新窗口中以及如何开启它我的第一个屏幕本身。还有什么方法可以拖放到表单来制作我的列和表头?我附上了代码:

using System;
using Gtk;
namespace ImageCompressionTool
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Application.Init ();
            MainWindow win = new MainWindow ();
            win.Show ();
            Application.Run ();

            Gtk.Application.Init ();
            NodeViewExample win1 = new NodeViewExample ();
            win1.Show ();
            Gtk.Application.Run ();

        }

    }
    public class MyTreeNode : Gtk.TreeNode {

        string song_title;

        public MyTreeNode (string artist, string song_title)
        {
            Artist = artist;
            this.song_title = song_title;
        }

        [Gtk.TreeNodeValue (Column=0)]
        public string Artist;

        [Gtk.TreeNodeValue (Column=1)]
        public string SongTitle {get { return song_title; } }

    }

    public class NodeViewExample : Gtk.Window {
        Gtk.NodeStore store;
        Gtk.NodeStore Store {
            get {
                if (store == null) {
                    store = new Gtk.NodeStore (typeof (MyTreeNode));
                    store.AddNode (new MyTreeNode ("The Beatles", "Yesterday"));
                    store.AddNode (new MyTreeNode ("Peter Gabriel", "In Your Eyes"));
                    store.AddNode (new MyTreeNode ("Rush", "Fly By Night"));
                }
                return store;
            }
        }

        public NodeViewExample () : base ("NodeView")
        {
            SetSizeRequest (200,150);

            // Create our TreeView and add it as our child widget
            Gtk.NodeView view = new Gtk.NodeView (Store);
            Add (view);

            // Create a column with title Artist and bind its renderer to model column 0
            view.AppendColumn ("Artist", new Gtk.CellRendererText (), "text", 0);

            // Create a column with title 'Song Title' and bind its renderer to model column 1
            view.AppendColumn ("Song Title", new Gtk.CellRendererText (), "text", 1);
            view.ShowAll ();
        }

    }


}

请帮助我。谢谢!

1 个答案:

答案 0 :(得分:0)

如果您只想显示NodeView窗口,请删除显示MainWindow的代码。您的Main方法当前显示两个窗口。如果您只是希望它显示您的NodeViewExample窗口,那么它应该如下所示:

    public static void Main (string[] args)
    {
        Gtk.Application.Init ();
        NodeViewExample win1 = new NodeViewExample ();
        win1.Show ();
        Gtk.Application.Run ();
    }

您无法将列拖放到设计器中的Gtk.NodeView或Gtk.TreeView中。