【发布时间】:2015-08-03 06:56:26
【问题描述】:
我试图将 GTK# 对话框放置在窗口的中心,并且我希望在出现此对话框时使父窗口不可编辑。
我尝试设置parent 属性和对话框并将其位置设置为center on parent。(父窗口位置始终居中,父窗口居中但其中一部分位于任务栏下方)
我做错了什么?
更新:
我尝试设置 transcientfor 属性。
mywin d = new mywin();
d.Parent = this;
d.WindowPosition = WindowPosition.CenterOnParent;
d.TransientFor = this;
d.WidthRequest = 360;
d.HeightRequest =260;
d.Resizable = false;
d.Show ();
当我这样做时,我在应用程序输出中也得到了这个错误
(myapp:5844): Gtk-WARNING **: Can't set a parent on a toplevel widget
(myapp:5844): Gdk-CRITICAL **: inner_clipboard_window_procedure: assertion 'success' failed
更新: 从父级调用对话框
protected void OnButton7Clicked (object sender, EventArgs e)
{
var mydiag = new mydiag( this );
if ( ( (Gtk.ResponseType) mydiag.Run() ) == Gtk.ResponseType.Ok ) {
// do whatever here...
}
}
对话框代码
using System;
namespace myproj
{
public partial class mydiag : Gtk.Dialog
{
public mydiag (Gtk.Window parent)
{
this.Build ();
this.Title = parent.Title + " more info";
this.Icon = parent.Icon;
this.Parent = parent;
this.TransientFor = parent;
this.SetPosition( Gtk.WindowPosition.CenterOnParent );
this.ShowAll();
}
}
}
【问题讨论】:
-
您是否将对话框设置为
transient_for父级? (如果您将父级作为parent参数传递给标准 GtkDialog 构造函数之一,则可以。) -
@andlabs 我也试过了。请查看更新。
-
Parent的属性与GtkWidget完全不同;它与GtkContainer有关。摆脱那条线。您使用的是什么操作系统和窗口管理器? -
@andlabs 我现在正在使用 Windows。但是该应用程序是为 Mac 设计的,这对如何管理窗口有任何影响。我不知道我正在使用什么窗口管理器。我只是使用 Xamarin Studio (单声道+Gtk#)