[MAUI] 윈도우 환경에서 팝업 윈도우들 관리하기

안녕하세요. 흑우마스터입니다.

사실 크게 별거는 없습니다. 새로운 윈도우를 띄우고자 하실 때 아래처럼 해주시면 되고

        List<Window> NewWindowList = new List<Window>(); 
        // 이렇게 안하고 App.Current.Windows  혹은 Application.Current.Windows 이 쪽에도 있긴합니다.
        Window secondWindow = new Window(new NewPage1());
        NewWindowList.Add(secondWindow);
        Application.Current.OpenWindow(secondWindow);

이미 활성화 되어 있는 윈도우를 해제할 수도 있습니다 (Window 컬렉션을 보관하는 NewWindowList가 있을경우)

            Application.Current.CloseWindow(NewWindowList.FirstOrDefault());
            NewWindowList.Remove(NewWindowList.FirstOrDefault());

하지만 여기까지는 간단할 수 있는데 팝업 된 윈도우들 중에 특정 윈도우를 최상단으로 올리거나 최소화 되어있는지 등 다양한 정보를 확인하실 땐 이렇게 구현 하셔야 됩니다

먼저 using Microsoft.Maui.Platform; 을 코드 상단에 정의해주신 후

#if WINDOWS
            MauiWinUIWindow platformView = (MauiWinUIWindow)NewWindowList.FirstOrDefault().Handler.PlatformView;
            var appWindow = platformView.GetAppWindow();

            switch (appWindow.Presenter)
            {
                case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                    //overlappedPresenter.IsMinimizable = !overlappedPresenter.IsMinimizable;
                    overlappedPresenter.IsAlwaysOnTop = true;
                    overlappedPresenter.IsAlwaysOnTop = false;
                    break;
            }       
#endif

이런 식으로 작성해주셔야 됩니다.

MAUI를 하는 친구가 윈도우 환경에서 메인 윈도우에서 특정 액션을 하면 팝업 된 윈도우들 중에서 해당하는 윈도우가 최상단으로 오게 해달라고 해서 알려준 코드긴한데 사실 이렇게까지 작업하는 분들이 별로 없다보니 필요하신 분도 있을까봐 공유 드려봅니다.

Presenter에는 현재 윈도우의 보여지는 상태 값들이 보이기 때문에 조건에 따라 다르게 설정하시면 될 것 같습니다.
감사합니다.

아. 뭔가 Focus를 주거나 다른게 있는 줄 알았는데 찾기 귀찮아서 최상단 고정을 줬다가 빼버리는 쪽으로 해결했습니다.

뭔가 정신없이 글을 쓰긴 했는데 회사라 ㅋㅋ… 급하게 작성했습니다

7개의 좋아요