Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #125 from whitneyschmidt/sample_fix
Browse files Browse the repository at this point in the history
Fix InvalidOperationException in MacWindows sample
  • Loading branch information
whitneyschmidt authored Dec 13, 2019
2 parents 30faa68 + ec84bf8 commit 9bd3c26
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
22 changes: 13 additions & 9 deletions MacWindows/MacWindows/MasterWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@

namespace MacWindows
{
public partial class MasterWindowController : NSWindowController
{
public partial class MasterWindowController : NSWindowController, INSWindowDelegate {
public MasterWindowController (IntPtr handle) : base (handle)
{
}

public override void WindowDidLoad ()
{
base.WindowDidLoad ();
Window.Delegate = this;
}

Window.DidResize += (sender, e) => {
// Do something as the window is being live resized
};
[Export ("windowDidResize:")]
public void DidResize (NSNotification notification)
{
// Do something as the window is being live resized
}

Window.DidEndLiveResize += (sender, e) => {
// Do something after the user's finished resizing
// the window
};
[Export ("windowDidEndLiveResize:")]
public void DidEndLiveResize (NSNotification notification)
{
// Do something after the user's finished resizing
// the window
}
}
}
28 changes: 16 additions & 12 deletions MacWindows/MacWindows/ViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MacWindows
{
public partial class ViewController : NSViewController
public partial class ViewController : NSViewController, INSWindowDelegate
{
#region Computed Properties
public override NSObject RepresentedObject {
Expand Down Expand Up @@ -45,24 +45,28 @@ public override void ViewDidLoad ()

}

[Export ("windowWillClose:")]
public void WillClose (NSNotification notification)
{
// is the window dirty?
if (DocumentEdited) {
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Critical,
InformativeText = "We need to give the user the ability to save the document here...",
MessageText = "Save Document",
};
alert.RunModal ();
}
}

public override void ViewWillAppear ()
{
base.ViewWillAppear ();

// Set Window Title
this.View.Window.Title = "untitled";

View.Window.WillClose += (sender, e) => {
// is the window dirty?
if (DocumentEdited) {
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Critical,
InformativeText = "We need to give the user the ability to save the document here...",
MessageText = "Save Document",
};
alert.RunModal ();
}
};
View.Window.Delegate = this;
}

public override void AwakeFromNib ()
Expand Down

0 comments on commit 9bd3c26

Please sign in to comment.