Xamarin.MacでStoryboard上のWindowをモーダルで出す
5193 ワード
忘備録として
単なる忘備録です。
今更感満載 です。
Xanarin.Macでウインドウをモーダルで出す
出すにしても、Storyboard上にある、NSWindowControllerに結びついているウインドウを出したりします。
主に使いそうなのは、環境設定... 用です。
StoryboardからNSWindowController(idつき)を引っ張り出す
InstantiateControllerWithIdentifier
を使います。
var wc = NSStoryboard.MainStoryboard.InstantiateControllerWithIdentifier("preference window") as NSWindowController;
モーダルで出す
RunModalForWindow
を使います。
NSApplication.SharedApplication.RunModalForWindow(wc.Window);
モーダルを閉じる
StopModal
と OrderOut
を使います。
NSApplication.SharedApplication.StopModal();
wc.Window.OrderOut(wc);
一連の流れを関数にする
メニューに関連づけます。
こんな感じになります。
partial void doPreferences(Foundation.NSObject sender)
{
var wc = NSStoryboard.MainStoryboard.InstantiateControllerWithIdentifier("preference window") as NSWindowController;
if (wc != null)
{
var closeButton = wc.Window.StandardWindowButton(NSWindowButton.CloseButton);
closeButton.Activated += (object clickSender, System.EventArgs e) =>
{
NSApplication.SharedApplication.StopModal();
(closeButton.AccessibilityParent as NSWindow).OrderOut(closeButton);
};
NSApplication.SharedApplication.RunModalForWindow(wc.Window);
}
}
なんで書いておくのか
Windowのクローズボタンからの処理に悩んだからです…。
なので、一番書きたかったのは、 StandardWindowButton
の部分だったりします。
Author And Source
この問題について(Xamarin.MacでStoryboard上のWindowをモーダルで出す), 我々は、より多くの情報をここで見つけました https://qiita.com/yakumomo/items/bc6e774745b7917c00f0著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .