February 5, 2009

Using Application Commands

These are standard application related commands, see here In Xaml:
    <CommandBinding Command="ApplicationCommands.Close"
  <Button Command="ApplicationCommands.Close" 
            Content="Close File" />
and in code:
// Executed event handler.
private void CloseCommandHandler(object sender, ExecutedRoutedEventArgs e)
    // Calls a method to close the file and release resources.

// CanExecute event handler.
private void CanExecuteHandler(object sender, CanExecuteRoutedEventArgs e)
    // Call a method to determine if there is a file open.
    // If there is a file open, then set CanExecute to true.
    if (IsFileOpened())
        e.CanExecute = true;
    // if there is not a file open, then set CanExecute to false.
        e.CanExecute = false;

No comments: