如何在 gtk 中设置 window 标题栏#

How to set window title bar in gtk#

我有一个问题,我想使用 header 栏作为 gtk# 中的标题栏,但这是创建的错误:

error CS1061: 'Window' does not contain a definition for 'gtk_window_set_titlebar' and no accessible extension method 'gtk_window_set_titlebar' accepting a first argument of type 'Window' could be found (are you missing a using directive or an assembly reference?)

这是我使用的 gtk#:GTK#

这是我的代码:

namespace gtkapp
{
    class MainWindow : Window
    {
        private int _counter = 0;
        static private int _max = 1000;


        [UI] private Label _label1 = null;
        [UI] private Label _label2 = null;
        [UI] private Button _button1 = null;
        [UI] private Button _button2 = null;
        [UI] private LevelBar lb = new LevelBar(0, _max);
        [UI] private HeaderBar _headerbar = null;
        [UI] private Window MainWindoww = null;

        public MainWindow() : this(new Builder("MainWindow.glade")) { }

        private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow"))
        {
            builder.Autoconnect(this);
            MainWindoww.gtk_window_set_titlebar(MainWindoww, _headerbar);
            DeleteEvent += Window_DeleteEvent;
            _button1.Clicked += Button1_Clicked;
            _button2.Clicked += Button2_Clicked;

            _headerbar.Title = "GTK clicker";

            Decorated = false;

            lb.Value = 0;
            lb.MaxValue = 1000000;
        }

        private void Window_DeleteEvent(object sender, DeleteEventArgs a)
        {
            Application.Quit();
        }

        private void Button1_Clicked(object sender, EventArgs a)
        {
            _counter++;
            // _counter += 100;
            lb.Value += 10;
            lb.MaxValue += 1;
            if(lb.Value < _max)
            {
                _label1.Text = "This GTK button has been clicked " + _counter + " time(s).";
            }
            else if(lb.Value >= _max)
            {
                _label1.Text = "This GTK button has been clicked for the " + _counter + " time(s).";
            }
        }

        private void Button2_Clicked(object sender, EventArgs a)
        {
            Application.Quit();
        }
    }
}

相当于gtk_window_set_titlebar()

我从评论中找到的解决方案。

use this.Titlebar = (the variable of the header bar, my variable name is _headerbar); Decotated = false;

顺序必须在上面,否则无效