我需要设置 View 首次打开时的默认大小,但 View 必须允许用户展开。 (由于其他原因,我无法在我的 WindowManager 中使用 SizeToContent 属性。)
这一定很常见,设置默认窗口大小的推荐方法是什么?
最佳答案
这实际上困扰了我一段时间。一旦我弄明白了,我就很生气,因为我没有早点弄明白。
在caliburn中显示窗口时,可以在调用时设置Window对象的属性。
那么,假设您想将窗口的高度和宽度设置为 600 x 300:
首先,您将从这样的事情开始:
public class ShellViewModel : PropertyChangedBase, IShell
{
private readonly IWindowManager windowManager;
public ShellViewModel()
{
this.windowManager = new WindowManager();
this.windowManager.ShowWindow(new LameViewModel());
}
}
ShowWindow 方法中还有另外两个字段。第三个参数允许您动态设置 Window 对象的属性。
public class ShellViewModel : PropertyChangedBase, IShell
{
private readonly IWindowManager windowManager;
public ShellViewModel()
{
this.windowManager = new WindowManager();
dynamic settings = new ExpandoObject();
settings.Height = 600;
settings.Width = 300;
settings.SizeToContent = SizeToContent.Manual;
this.windowManager.ShowWindow(new LameViewModel(), null, settings);
}
}
我希望在文档中有更多关于使用它的信息,但现在已经有了。
关于c# - 在 Caliburn.micro 中设置初始窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16404538/