Forum Xamarin.Mac

New Window open in Appdelegate _MessageReceived Event

DineshDDineshD Member ✭✭

in Xamarin.Mac _MessageReceived event i get the message. but i can't able to open that message to new window. is it possible in AppDelegate file.

I am using
// Get new window
var storyboard = NSStoryboard.FromName("Main", null);
var controller = storyboard.InstantiateControllerWithIdentifier("MainWindow") as NSWindowController;

                      // Display
                      controller.ShowWindow(this);

but its does not works.

Best Answer

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    but its does not works. does not give much information for people on the forum.

    Did crash? Print an error? Throw an exception? Silently fail.

    There are a number of examples of similar code working, such as https://github.com/xamarin/mac-samples/blob/master/MacControls/MacControls/AppDelegate.cs#L36

    so without more details no one will be able to help you.

  • DineshDDineshD Member ✭✭
    edited February 10

    when i use that code on message received event in appdelegate Xamarin.MacOS. I got "AppKit Consistency error: you are calling a method that can only be invoked from the UI thread." this error.

    I Used

               // Get new window
                var storyboard1 = NSStoryboard.FromName("Main", null);
                var controller1 = storyboard1.InstantiateControllerWithIdentifier("MainWindow") as NSWindowController;
    
                // Display
                controller1.ShowWindow(this);
    
                // Set the title
                controller1.Window.Title = (++UntitledWindowCount == 1) ? "untitled" : string.Format("untitled {0}", UntitledWindowCount);
    
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    AppKit Consistency error: you are calling a method that can only be invoked from the UI thread

    means exactly what it says. The code is being invoked on not the main thread, and AppKit requires all UI code to be on the main thread. Use BeginInvokeOnMainThread to something similar to thread switch.

  • DineshDDineshD Member ✭✭

    BeginInvokeOnMainThread support with only IOS not Macos...
    if it support in MacOS can you show me some samples.

  • DineshDDineshD Member ✭✭

    thanks lots Chris Hamons your support.... Its Works..

    Regards
    Dinesh D

Sign In or Register to comment.