thexamlguy / NotificationFlyout

MIT License
0 stars 0 forks source link

Question: How to set Window state to WindowState.Normal #7

Closed Noemata closed 3 years ago

Noemata commented 3 years ago

To get the behavior I was looking for, I added to NotificationFlyoutApplication.cs the following:

        public void NormalizeWindowState<TUIElement>() where TUIElement : Windows.UI.Xaml.UIElement
        {
            var window = new XamlHost<TUIElement>();

            if (window.WindowState == WindowState.Minimized)
                window.WindowState = WindowState.Normal;
        }

... in Shell.xaml.cs

        private void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var app = GetApplication();

            if (!App.IsWindowContentShown)
                app.OpenAsWindow<WindowContent>();
            else
                app.NormalizeWindowState<WindowContent>();
        }

I call this method if the WindowsContent window has been created with the expectation that if the window had been minimized, it will be brought back up. When this method gets called, irrespective of the fact that the WindowsContent window has been minimized, the state is always "Normal", so my conditional check fails.

Any ideas why this is the case? Is it a XAML Islands limitation?

Noemata commented 3 years ago

Never mind, the following resolved the issue:

        public void NormalizeWindowState<TUIElement>() where TUIElement : Windows.UI.Xaml.UIElement
        {
            var window = new XamlHost<TUIElement>();

            //if (window.WindowState == WindowState.Minimized)
            window.WindowState = WindowState.Normal;
            window.Show();
        }
Noemata commented 3 years ago

Thanks a bunch Daniel, I now have exactly what I was looking for. Fantastic!

I added some bits to have a Singleton style main window that gets recreated if closed.