Is there a Close command for dialog boxes in the WPF command framework?

Should I use ApplicationCommands.Closeto close modal dialogs or is this command considered reserved to close the application? If this is the last, do you create commands Closefor each Dialogor only one command Closefor all your modal dialogs?

+3
source share
3 answers

This is how WPF uses ApplicationCommand.Close:

  • WPF itself does not have a built-in command handler for ApplicationCommands.Close, but
  • WPF ApplicationCommand.Close RoutedCommand , Win32 WM_APPCOMMAND lParam=APPCOMMAND_CLOSE. , - Win32 APPCOMMAND_CLOSE, ApplicationCommand.Close.

APPCOMMAND_CLOSE :

( ).

, WPF ApplicationCommand.Close "" ( , Win32).

, Win32? :

  • Accessibilty
  • " "
  • " "

, : , ApplicationCommand.Close . - , . .

App.xaml, CommandBinding thw Window, ((Window)sender).Close(). .

+2

, , , IsCancel :

<Button IsCancel="True">Cancel</Button>

, false. true, - (2) . XAML:

<Button IsDefault="True" Click="acceptButton_Click">OK</Button>

:

void acceptButton_Click(object sender, RoutedEventArgs e)
{
    this.DialogResult = true;
}

true.

( ), - MVVM-. YDMV.

+2

.

. "X" Window, . "X", "DialogCancelCommand" , OnDialogCancel Window. , , "DialogCancelCommand" RoutedEvent. , "DialogCancelCommand" Reflected code, , .

    /// <summary>
    /// Cancels a dialog.
    /// </summary>
    public static readonly RoutedCommand DialogCancelCommand = new RoutedCommand("DialogCancel", typeof(CoreCommands));
+1

Source: https://habr.com/ru/post/1751100/


All Articles