GTK# window not rendered completely

六眼飞鱼酱① 提交于 2019-12-12 22:04:03

问题


Right now, I am trying to develop a program using Mono and GTK# on a Debian (Raspbian) system.

The issue I'm facing is, that, completely randomly, the GUI (generated by the Stetic designer or its dynamic elements) isn't completely drawn, missing either a few characters from a Label-element or whole widgets, mostly those that were dynamically created. This is how it looks on a dialog window: http://imgur.com/oEZRg7c (text is cut off)

As soon as one window shows this issue, every other window has the same issues, sometimes missing whole widgets, even if those were created afterwards. The solution is usually to quit the program and reopen it, as it only randomly occurs.

This is how the constructor of most of my windows looks like (the part after Build() varies):

public partial class ErrorSolutionDialog : Gtk.Dialog
{
    public ErrorSolutionDialog (string errorMessage, string solutionHint)
    {
        this.WidthRequest = this.Screen.Width;
        this.HeightRequest = this.Screen.Height;
        this.Maximize ();
        this.Fullscreen ();
        this.KeepAbove = true;
        this.DestroyWithParent = false;
        Build ();

        this.ErrorMessage.Markup = "<b><span size='xx-large'>" + errorMessage + "</span></b>";
        this.SolutionHint.Text = solutionHint;
    }
}

回答1:


I wouldn't say that the use of the Stetic designer inside Xamarin Studio/Monodevelop is bad, but as any piece of software it certainly has some issues.

Also, the use of any designer in any software environment will tie you to that development platform forever. Finally, the created source code will be hardly maintainable, apart from completely foreign for you.

That's why I always recommend to get rid of the designer. You can follow a Gtk# tutorial such as this one, and you'll find it is easy and rewarding. And you'll have whole and thorough control of your code.

The basics about Gtk# is creating a layout with VBoxes and HBoxes. For example, the following code creates a layout in which you'll have a TreeView and a TextView in a Dialog.

var swWin1 = new Gtk.ScrollWindow();
var swWin2 = new Gtk.ScrollWindow();

// TextView
this.txtView = new Gtk.TextView();
swWin1.AddWithViewport( this.txtView );

// TreeView
this.tvView = new Gtk.TreeView();
swWin2.AddWithViewport( this.tvView );

// Layout
var hBox = new HBox( false, 2 );
hBox.PackStart( swWin1, true, true, 5 );
hBox.PackStart( swWin2, true, true, 5 );
this.VBox.PackStart( hBox, true, true, 5 );

PackStart() is the method doing the magic in order to add a widget to a layout. The booleans tell Gtk to expand the widget. A ScrollWindow adds scrollbars to any widget.

Finally, my advice is for any action, use Gtk.Action, and call its methods CreateMenuItem() and CreateToolItem() in order to create menu entries and toobar buttons, instead of repeating the same code again and again.

Hope this helps.



来源:https://stackoverflow.com/questions/31875860/gtk-window-not-rendered-completely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!