wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Close to tray feature

Open Jimex opened this issue 4 years ago • 3 comments

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

Thank you.

Jimex avatar May 06 '22 00:05 Jimex

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

pomianowski avatar May 06 '22 07:05 pomianowski

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; }

Jimex avatar May 06 '22 11:05 Jimex

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();

Marplex avatar Jun 20 '22 09:06 Marplex

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>

christian-photo avatar Oct 31 '22 16:10 christian-photo