c# - 在 Xamarin.Mac 中从其他人打开新的自定义窗口
问题描述
我的应用程序中有两个自定义的 NSWindow,如下所示:
窗口 1:
public partial class LoginVindow : NSWindow
{
public LoginVindow (IntPtr handle) : base (handle)
{
}
}
窗口 2:
public partial class OperationWindow : NSWindow
{
public OperationWindow (IntPtr handle) : base (handle)
{
}
}
现在,我想在单击按钮后关闭第一个窗口并打开第二个窗口。但是,此代码无法为我运行。
partial void LoginButton_Clicked(Foundation.NSObject sender)
{
Window.Close(); // Closes the first login window.
var operation_window = new OperationWindow(Handle); // Gets the second Window. IntPtr parameter is required unlike the internet codeblocks.
operation_window.ShowWindow(this); // No any method like this.
}
互联网上的所有代码块似乎都适用于非自定义的标准类 NSWindow 项目,但其中一个对我来说似乎是稳定的。但是,它没有运行。(在 Xamarin 论坛中发帖:https ://forums.xamarin.com/discussion/122359/open-and-close-window-programmatically-xamarin-mac )
我该如何处理这个操作?请帮忙,谢谢。
解决方案
这个代码块解决了我的问题。谢谢。
// Get new window
var storyboard = NSStoryboard.FromName("Main", null);
var controller = storyboard.InstantiateControllerWithIdentifier("OperationsWindow") as NSWindowController;
controller.ShowWindow(this);
this.Window.Close();
推荐阅读
- javascript - Javascript - 查找字符串上的左括号和右括号位置?
- python - 如何将索引号反转为它在 Python 中表示的字符?
- search - 在 H 列中搜索日期并使用谷歌应用脚本将其替换为当前日期
- javascript - 从数组中获取基于相同 id 的对象
- java - 按用户名删除spring boot
- node.js - 多个客户端(网站和应用程序)的 API 身份验证
- python - EEL 等待本地主机
- https - 通过 Squid 代理的 HTTPS 请求超时
- jquery - 在 $(window).on('load', function() 之后加载图像
- amazon-web-services - AccessDeniedException 删除 EKS 集群时出错