lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.67k stars 748 forks source link

Close to tray feature #166

Open Jimex opened 2 years ago

Jimex commented 2 years ago

Can we have a function that minimizes the window to the tray after clicking the close icon?

Thank you.

pomianowski commented 2 years ago

Hey @Jimex, initially, such functionality is implemented, but does not work properly yet.

https://github.com/lepoco/wpfui/blob/bece9fb2815ca8fe4bb66fb70454d0f10d8f40b7/src/WPFUI/Controls/TitleBar.cs#L369

Jimex commented 2 years ago

Hey @Jimex, initially, such functionality is implemented, but does not work properly yet.

https://github.com/lepoco/wpfui/blob/bece9fb2815ca8fe4bb66fb70454d0f10d8f40b7/src/WPFUI/Controls/TitleBar.cs#L369 Yea I have tried this, but when I called this method from my code, the window still closed though.

private void TitleBar_OnCloseClicked(object sender, RoutedEventArgs e) { MinimizeWindow(true); e.Handled = true; }

Marplex commented 2 years ago

Hi @Jimex, the MinimizeWindow() method is working. It's just that the click event is also handled by TemplateButton_OnClick https://github.com/lepoco/wpfui/blob/1ffa8c2466ee107215d341310afe17e4a3a97791/src/Wpf.Ui/Controls/TitleBar.cs#L616-L618

@pomianowski I would suggest to add a new property like IsCloseDefaultActionDisabled and skip the CloseWindow() when true. If that's ok, I can work on this.

RaiseEvent(new RoutedEventArgs(CloseClickedEvent, this));
if(!IsCloseDefaultActionDisabled) CloseWindow();
christian-photo commented 2 years ago

Hey, Are there any updates on this or is there a workaround to control wheter the window should close or just minimize to tray?

Edit: I found a workaround, this will only close the window when shift is pressed. If shift is not pressed, it will minimize the window to the tray

        private void UiWindow_Closing(object sender, CancelEventArgs e)
        {
            if (Keyboard.GetKeyStates(Key.LeftShift) == KeyStates.Down)
            {
                Application.Current.Shutdown();
                return;
            }
            e.Cancel = true;
            Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            WindowState = WindowState.Minimized;
            Hide();
        }
<ui:UiWindow
    ....
   Closing="UiWindow_Closing"
    ....>
</ui:UiWindow>