「Xamarin.Macでモーダルウインドウを作成する」の版間の差分

57行目: 57行目:
         }
         }
     }
     }
</source>
なお、NSApplication.SharedApplication.StopModalWithCodeはウインドウのモーダル化が解除されるだけでウインドウ自体は閉じない。ボタンなどを押されたときにモーダルウインドウを閉じる場合にはthis.Window.Closeを呼んでやると良いようだ。
<source lang="csharp">
        ModalResult _result = ModalResult.Cancel;
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            // ----------------------------------------------------
            this.Window.WillClose += (object sender, EventArgs e) => {
                Console.WriteLine("WillClose");
                NSApplication.SharedApplication.StopModalWithCode((int)_result);
            };
            cancelButton.Activated += (object sender, EventArgs e) => {
                Console.WriteLine("cancelButton");
                _result = ModalResult.Cancel;
                this.Window.Close();
            };
            okButton.Activated += (object sender, EventArgs e) => {
                Console.WriteLine("okButton");
                _result = ModalResult.OK;
                this.Window.Close();
            };
        }
</source>
</source>