Forum Xamarin.Mac

Is it possible to display the same window multiple times?

RobAlemRobAlem Member ✭✭

I'm trying to accomplish having the same window open on all connected screens/displays. They also have to be in sync with each other, e.g. if properties on Window1 change, they need to change on Window2 as well, preferably using Mvvm.

The code below only shows a single window on the last screen in the screens list. This happens because MainWindow gets overwritten in every iteration of the foreach loop. So that means the code ain't doing what I intent to do and I know why. I just attached it for some clarification. All I need to know is if what I'm trying to accomplish is possible.

public class AppDelegate : FormsApplicationDelegate
{
    public override NSWindow MainWindow => window;
    private readonly List<NSScreen> screens = new List<NSScreen>(NSScreen.Screens); // List with all screens currently active
    private NSWindow window;

    public AppDelegate()
    {
        var style = NSWindowStyle.Borderless;
        foreach (var screen in screens)
        {
            var x = screen.VisibleFrame.GetMaxX();
            var y = screen.VisibleFrame.GetMaxY();
            var rect = new CGRect(x - 320, y - 220, 300, 200); // Place window top-right of the screen with margin of 20
            window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
            window.Level = NSWindowLevel.ScreenSaver; // Forces window to keep on top
        }
    }

    public override void DidFinishLaunching(NSNotification notification)
    {
        Forms.Forms.Init();
        LoadApplication(new App()); // App.xaml is located in a different project
        base.DidFinishLaunching(notification);
    }
}

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    The same instance will have a problem because it can't have two different parents... they each need to size themselves to different windows of different geometries, different magnification properties and pixel densities and so on.
    So just use two instances and bind them both to the same ViewModel.

  • RobAlemRobAlem Member ✭✭

    @ClintStLaurent said:
    So just use two instances and bind them both to the same ViewModel.

    By that you mean two instances of NSWindow?

Sign In or Register to comment.