c# – 无法使用Gtk Builder加载glade文件. Gtk3#
发布时间:2020-12-15 22:22:10 所属栏目:百科 来源:网络整理
导读:(注意:我没有写这个代码,它是从一个插件项目模板生成的) 当我尝试使用带有Gtk#的GTK Builder来加载glade文件时,会抛出一个异常,即文件必须以元素开头. 错误: GLib.GException has been thrownError on line 1 char 1: Document must begin with an element
(注意:我没有写这个代码,它是从一个插件项目模板生成的)
当我尝试使用带有Gtk#的GTK Builder来加载glade文件时,会抛出一个异常,即文件必须以元素开头. 错误: GLib.GException has been thrown Error on line 1 char 1: Document must begin with an element (e.g. <book>) MainWindow.glade: <?xml version="1.0" encoding="UTF-8"?> <interface> <requires lib="gtk+" version="3.0" /> <object class="GtkWindow" id="window1"> <property name="can_focus">False</property> <child> <object class="GtkBox" id="box1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> <object class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="yalign">0.47999998927116394</property> <property name="label" translatable="yes">Hello World! This button has been clicked 0 time(s).</property> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkButton" id="button1"> <property name="label" translatable="yes">Click me!</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="receives_default">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> </child> </object> </interface> MainWindow.cs: using System; using Gtk; using UI = Gtk.Builder.ObjectAttribute; public partial class MainWindow: Gtk.Window { Builder builder; [UI] Gtk.Button button1; [UI] Gtk.Label label1; int clickedTimes; public static MainWindow Create () { Builder builder = new Builder (null,"DiscordEditor.interfaces.MainWindow.glade",null); return new MainWindow (builder,builder.GetObject ("window1").Handle); } protected MainWindow (Builder builder,IntPtr handle) : base (handle) { this.builder = builder; builder.Autoconnect (this); DeleteEvent += OnDeleteEvent; button1.Clicked += onButtonClick; } protected void onButtonClick (object sender,EventArgs a) { clickedTimes++; label1.Text = string.Format ("Hello World! This button has been clicked {0} time(s).",clickedTimes); } protected void OnDeleteEvent (object sender,DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } } 我不明白为什么会发生这种情况,除非它是GTK#3的一个错误,因为它尚未完全发布.我真的想用GTK3代替GTK2,所以有人会建议吗? 编辑:我通过打开生成的文件并将其保存为GTKBuilder格式来修复它. 解决方法
我在外部修改glade文件时遇到了同样的错误.这是因为我使用的是一个我归零的缓冲区,并没有正确设置实际的文件大小.我认为这不重要,但设置eof正确修复了错误.不确定它是否与你的相同(多年以后这不重要)但也许是因为类似的东西.似乎是gtk的glade阅读器中的一个错误不是非常强大.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – 导致此无效日期错误的原因是什么?
- ios – 获取WKWebView的当前内存使用情况?
- c# – .ToShortDateString返回不同于预期的文化格式
- 如何在Ruby中访问原始命令行参数字符串?
- ruby-on-rails-3 – 在Haml中将变量打印到控制台以调试Rspe
- Cocos2d-x 3.2 大富翁游戏项目开发-第十七部分 Toast提示框
- C#实现将类的内容写成JSON格式字符串的方法
- Native/Hybrid/Web App
- 领域驱动设计(DDD)实现之路
- ruby-on-rails-3 – 在Cucumber / Capybara / Selenium中发