jpbochi
jpbochi

Reputation: 4406

WPF Built-in Commands

I'm looking for a complete list of built-in WPF Commands.

The best list I've found so far is here, but it does not list all commands.

Some nice-to-have details would be:

Upvotes: 34

Views: 23369

Answers (4)

Luiz
Luiz

Reputation: 108

Since apparently no one's done that, here's a table with all the WPF commands with their gestures, generated by a modified version the code in Ray Burns's answer:

Command Type Gestures
ApplicationCommands.CancelPrint RoutedUICommand
ApplicationCommands.Close RoutedUICommand
ApplicationCommands.ContextMenu RoutedUICommand Shift+F10, Apps
ApplicationCommands.Copy RoutedUICommand Control+C, Control+Insert
ApplicationCommands.CorrectionList RoutedUICommand
ApplicationCommands.Cut RoutedUICommand Control+X, Shift+Delete
ApplicationCommands.Delete RoutedUICommand Delete
ApplicationCommands.Find RoutedUICommand Control+F
ApplicationCommands.Help RoutedUICommand F1
ApplicationCommands.New RoutedUICommand Control+N
ApplicationCommands.NotACommand RoutedUICommand
ApplicationCommands.Open RoutedUICommand Control+O
ApplicationCommands.Paste RoutedUICommand Control+V, Shift+Insert
ApplicationCommands.Print RoutedUICommand Control+P
ApplicationCommands.PrintPreview RoutedUICommand Control+F2
ApplicationCommands.Properties RoutedUICommand F4
ApplicationCommands.Redo RoutedUICommand Control+Y
ApplicationCommands.Replace RoutedUICommand Control+H
ApplicationCommands.Save RoutedUICommand Control+S
ApplicationCommands.SaveAs RoutedUICommand
ApplicationCommands.SelectAll RoutedUICommand Control+A
ApplicationCommands.Stop RoutedUICommand Escape
ApplicationCommands.Undo RoutedUICommand Control+Z
ComponentCommands.ExtendSelectionDown RoutedUICommand Shift+Down
ComponentCommands.ExtendSelectionLeft RoutedUICommand Shift+Left
ComponentCommands.ExtendSelectionRight RoutedUICommand Shift+Right
ComponentCommands.ExtendSelectionUp RoutedUICommand Shift+Up
ComponentCommands.MoveDown RoutedUICommand Down
ComponentCommands.MoveFocusBack RoutedUICommand Control+Left
ComponentCommands.MoveFocusDown RoutedUICommand Control+Down
ComponentCommands.MoveFocusForward RoutedUICommand Control+Right
ComponentCommands.MoveFocusPageDown RoutedUICommand Control+Next
ComponentCommands.MoveFocusPageUp RoutedUICommand Control+PageUp
ComponentCommands.MoveFocusUp RoutedUICommand Control+Up
ComponentCommands.MoveLeft RoutedUICommand Left
ComponentCommands.MoveRight RoutedUICommand Right
ComponentCommands.MoveToEnd RoutedUICommand End
ComponentCommands.MoveToHome RoutedUICommand Home
ComponentCommands.MoveToPageDown RoutedUICommand Next
ComponentCommands.MoveToPageUp RoutedUICommand PageUp
ComponentCommands.MoveUp RoutedUICommand Up
ComponentCommands.ScrollByLine RoutedUICommand
ComponentCommands.ScrollPageDown RoutedUICommand Next
ComponentCommands.ScrollPageLeft RoutedUICommand
ComponentCommands.ScrollPageRight RoutedUICommand
ComponentCommands.ScrollPageUp RoutedUICommand PageUp
ComponentCommands.SelectToEnd RoutedUICommand Shift+End
ComponentCommands.SelectToHome RoutedUICommand Shift+Home
ComponentCommands.SelectToPageDown RoutedUICommand Shift+Next
ComponentCommands.SelectToPageUp RoutedUICommand Shift+PageUp
DataGrid.DeleteCommand RoutedUICommand Delete
DataGrid.SelectAllCommand RoutedUICommand Control+A
DocumentViewer.FitToHeightCommand RoutedUICommand
DocumentViewer.FitToMaxPagesAcrossCommand RoutedUICommand
DocumentViewer.FitToWidthCommand RoutedUICommand
DocumentViewer.ViewThumbnailsCommand RoutedUICommand
EditingCommands.AlignCenter RoutedUICommand
EditingCommands.AlignJustify RoutedUICommand
EditingCommands.AlignLeft RoutedUICommand
EditingCommands.AlignRight RoutedUICommand
EditingCommands.Backspace RoutedUICommand
EditingCommands.CorrectSpellingError RoutedUICommand
EditingCommands.DecreaseFontSize RoutedUICommand
EditingCommands.DecreaseIndentation RoutedUICommand
EditingCommands.Delete RoutedUICommand
EditingCommands.DeleteNextWord RoutedUICommand
EditingCommands.DeletePreviousWord RoutedUICommand
EditingCommands.EnterLineBreak RoutedUICommand
EditingCommands.EnterParagraphBreak RoutedUICommand
EditingCommands.IgnoreSpellingError RoutedUICommand
EditingCommands.IncreaseFontSize RoutedUICommand
EditingCommands.IncreaseIndentation RoutedUICommand
EditingCommands.MoveDownByLine RoutedUICommand
EditingCommands.MoveDownByPage RoutedUICommand
EditingCommands.MoveDownByParagraph RoutedUICommand
EditingCommands.MoveLeftByCharacter RoutedUICommand
EditingCommands.MoveLeftByWord RoutedUICommand
EditingCommands.MoveRightByCharacter RoutedUICommand
EditingCommands.MoveRightByWord RoutedUICommand
EditingCommands.MoveToDocumentEnd RoutedUICommand
EditingCommands.MoveToDocumentStart RoutedUICommand
EditingCommands.MoveToLineEnd RoutedUICommand
EditingCommands.MoveToLineStart RoutedUICommand
EditingCommands.MoveUpByLine RoutedUICommand
EditingCommands.MoveUpByPage RoutedUICommand
EditingCommands.MoveUpByParagraph RoutedUICommand
EditingCommands.SelectDownByLine RoutedUICommand
EditingCommands.SelectDownByPage RoutedUICommand
EditingCommands.SelectDownByParagraph RoutedUICommand
EditingCommands.SelectLeftByCharacter RoutedUICommand
EditingCommands.SelectLeftByWord RoutedUICommand
EditingCommands.SelectRightByCharacter RoutedUICommand
EditingCommands.SelectRightByWord RoutedUICommand
EditingCommands.SelectToDocumentEnd RoutedUICommand
EditingCommands.SelectToDocumentStart RoutedUICommand
EditingCommands.SelectToLineEnd RoutedUICommand
EditingCommands.SelectToLineStart RoutedUICommand
EditingCommands.SelectUpByLine RoutedUICommand
EditingCommands.SelectUpByPage RoutedUICommand
EditingCommands.SelectUpByParagraph RoutedUICommand
EditingCommands.TabBackward RoutedUICommand
EditingCommands.TabForward RoutedUICommand
EditingCommands.ToggleBold RoutedUICommand
EditingCommands.ToggleBullets RoutedUICommand
EditingCommands.ToggleInsert RoutedUICommand
EditingCommands.ToggleItalic RoutedUICommand
EditingCommands.ToggleNumbering RoutedUICommand
EditingCommands.ToggleSubscript RoutedUICommand
EditingCommands.ToggleSuperscript RoutedUICommand
EditingCommands.ToggleUnderline RoutedUICommand
MediaCommands.BoostBass RoutedUICommand
MediaCommands.ChannelDown RoutedUICommand
MediaCommands.ChannelUp RoutedUICommand
MediaCommands.DecreaseBass RoutedUICommand
MediaCommands.DecreaseMicrophoneVolume RoutedUICommand
MediaCommands.DecreaseTreble RoutedUICommand
MediaCommands.DecreaseVolume RoutedUICommand
MediaCommands.FastForward RoutedUICommand
MediaCommands.IncreaseBass RoutedUICommand
MediaCommands.IncreaseMicrophoneVolume RoutedUICommand
MediaCommands.IncreaseTreble RoutedUICommand
MediaCommands.IncreaseVolume RoutedUICommand
MediaCommands.MuteMicrophoneVolume RoutedUICommand
MediaCommands.MuteVolume RoutedUICommand
MediaCommands.NextTrack RoutedUICommand
MediaCommands.Pause RoutedUICommand
MediaCommands.Play RoutedUICommand
MediaCommands.PreviousTrack RoutedUICommand
MediaCommands.Record RoutedUICommand
MediaCommands.Rewind RoutedUICommand
MediaCommands.Select RoutedUICommand
MediaCommands.Stop RoutedUICommand
MediaCommands.ToggleMicrophoneOnOff RoutedUICommand
MediaCommands.TogglePlayPause RoutedUICommand
NavigationCommands.BrowseBack RoutedUICommand Alt+Left, Back
NavigationCommands.BrowseForward RoutedUICommand Alt+Right, Shift+Back
NavigationCommands.BrowseHome RoutedUICommand Alt+Home, BrowserHome
NavigationCommands.BrowseStop RoutedUICommand Alt+Escape, BrowserStop
NavigationCommands.DecreaseZoom RoutedUICommand
NavigationCommands.Favorites RoutedUICommand Control+I
NavigationCommands.FirstPage RoutedUICommand
NavigationCommands.GoToPage RoutedUICommand
NavigationCommands.IncreaseZoom RoutedUICommand
NavigationCommands.LastPage RoutedUICommand
NavigationCommands.NavigateJournal RoutedUICommand
NavigationCommands.NextPage RoutedUICommand
NavigationCommands.PreviousPage RoutedUICommand
NavigationCommands.Refresh RoutedUICommand F5
NavigationCommands.Search RoutedUICommand F3
NavigationCommands.Zoom RoutedUICommand
Slider.DecreaseLarge RoutedCommand
Slider.DecreaseSmall RoutedCommand
Slider.IncreaseLarge RoutedCommand
Slider.IncreaseSmall RoutedCommand
Slider.MaximizeValue RoutedCommand
Slider.MinimizeValue RoutedCommand
SystemCommands.CloseWindowCommand RoutedCommand
SystemCommands.MaximizeWindowCommand RoutedCommand
SystemCommands.MinimizeWindowCommand RoutedCommand
SystemCommands.RestoreWindowCommand RoutedCommand
SystemCommands.ShowSystemMenuCommand RoutedCommand

The code (I just put this in an empty WPF project):

var list = (
    from assembly in AppDomain.CurrentDomain.GetAssemblies()
    from type in assembly.GetTypes()
    from prop in type.GetProperties()
    where
        typeof(ICommand).IsAssignableFrom(prop.PropertyType) &&
        prop.GetAccessors()[0].IsStatic
    let commandType = prop.PropertyType.Name
    let gestures =
        typeof(RoutedCommand).IsAssignableFrom(prop.PropertyType) ?
        ((RoutedCommand)prop.GetValue(null)).InputGestures :
        null
    let gestureString = gestures != null
        ? string.Join(", ", gestures.Cast<InputGesture>().Select(g =>
        {
            if (g is KeyGesture kg)
            {
                return (kg.Modifiers == ModifierKeys.None ? "" : (kg.Modifiers.ToString() + "+")) + kg.Key.ToString();
            }
            else
            {
                return g.ToString();
            }
        }))
        : ""
    orderby type.Name, prop.Name
    select type.Name + "." + prop.Name + "\t" + commandType + "\t" + gestureString
);

var str = String.Join("\n", list);

Debug.WriteLine(str);

Upvotes: 1

Ray Burns
Ray Burns

Reputation: 62929

It is easy to display a complete list of all commands in all loaded assemblies:

  public string[] GetAllCommands()
  {
    return (
      from assembly in AppDomain.CurrentDomain.GetAssemblies()
      from type in assembly.GetTypes()
      from prop in type.GetProperties()
      where
        typeof(ICommand).IsAssignableFrom(prop.PropertyType) &&
        prop.GetAccessors()[0].IsStatic
      orderby type.Name, prop.Name
      select type.Name + "." + prop.Name
    ).ToArray();
  }

With PresentationFramework loaded I get the list at the bottom of this answer, which you will see is absolutely complete.

If you also want to see the command type (eg RoutedUIComand) and gestures, you can add this to the LINQ:

      let commandType = prop.PropertyType

      let gestures =
        typeof(UIElement).IsAssignableFrom(commandType) ?
          ((UIElement)prop.GetValue(null)).InputGestures :
        null

Then your select might be something like this:

      select type.Name + "." + prop.Name + " " + commandType.Name + " " + gestures

Programmatically finding out which controls do something with a given command is also possible. Basically something like this ought to work (not tried, but this will give you the idea):

var allCommands = (
  from assembly in AppDomain.CurrentDomain.GetAssemblies()
  from type in assembly.GetTypes()
  from prop in type.GetProperties()
  where
    typeof(ICommand).IsAssignableFrom(prop.PropertyType) &&
    prop.GetAccessors()[0].IsStatic
  orderby type.Name, prop.Name
  select new
  {
    typeName = type.Name,
    propName = prop.Name,
    displayAs = type.Name + "." + prop.Name,
  }
).ToArray();

var classesReferencingCommand = (
  from assembly in AppDomain.CurrentDomain.GetAssemblies()
  from type in assembly.GetTypes()
  from method in type.GetMethods()
  let methodBodyString = ConvertILToString(method.MethodBody.GetILAsByteArray())
  let info = new
  {
    typeName = type.FullName,
    referencedCommands =
      from cmd in allCommands
      where
        methodBodyString.Contains(cmd.typeName) &&
        methodBodyString.Contains(cmd.propName)
      select cmd
  }
  where info.commands.Any()
  select info
).ToArray();

where ConvertILToString would probably be something like this:

static string ConvertILToString(byte[] bytes)
{
  return new string(bytes.Where(b => b!=0).Select(b => (char)b).ToArray());
}

The results can be used any way you like, for example they can be displayed using an ItemsControl:

<ItemsControl Source="{Binding classesReferencingCommand}">
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <StackPanel>
        <TextBox Text="{Binding typeName}" FontWeight="Bold">
        <ItemsControl Source="{Binding referencedCommands}" Margin="10 0 0 0">
          <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBox Text="{Binding displayAs}" />
      ... close all tags ...

Alternatively you could output the data in a text or XML format or add it to a database. Also note that this second query can be turned around with the command iteration on the outside if you prefer a listing by command.

The code above will give you the precise facts and will not lie, because it is looking at the NET Framework itself.

Here is the promised list of all commands in PresentationFramework:

ApplicationCommands.CancelPrint
ApplicationCommands.Close
ApplicationCommands.ContextMenu
ApplicationCommands.Copy
ApplicationCommands.CorrectionList
ApplicationCommands.Cut
ApplicationCommands.Delete
ApplicationCommands.Find
ApplicationCommands.Help
ApplicationCommands.New
ApplicationCommands.NotACommand
ApplicationCommands.Open
ApplicationCommands.Paste
ApplicationCommands.Print
ApplicationCommands.PrintPreview
ApplicationCommands.Properties
ApplicationCommands.Redo
ApplicationCommands.Replace
ApplicationCommands.Save
ApplicationCommands.SaveAs
ApplicationCommands.SelectAll
ApplicationCommands.Stop
ApplicationCommands.Undo
ComponentCommands.ExtendSelectionDown
ComponentCommands.ExtendSelectionLeft
ComponentCommands.ExtendSelectionRight
ComponentCommands.ExtendSelectionUp
ComponentCommands.MoveDown
ComponentCommands.MoveFocusBack
ComponentCommands.MoveFocusDown
ComponentCommands.MoveFocusForward
ComponentCommands.MoveFocusPageDown
ComponentCommands.MoveFocusPageUp
ComponentCommands.MoveFocusUp
ComponentCommands.MoveLeft
ComponentCommands.MoveRight
ComponentCommands.MoveToEnd
ComponentCommands.MoveToHome
ComponentCommands.MoveToPageDown
ComponentCommands.MoveToPageUp
ComponentCommands.MoveUp
ComponentCommands.ScrollByLine
ComponentCommands.ScrollPageDown
ComponentCommands.ScrollPageLeft
ComponentCommands.ScrollPageRight
ComponentCommands.ScrollPageUp
ComponentCommands.SelectToEnd
ComponentCommands.SelectToHome
ComponentCommands.SelectToPageDown
ComponentCommands.SelectToPageUp
DocumentViewer.FitToHeightCommand
DocumentViewer.FitToMaxPagesAcrossCommand
DocumentViewer.FitToWidthCommand
DocumentViewer.ViewThumbnailsCommand
EditingCommands.AlignCenter
EditingCommands.AlignJustify
EditingCommands.AlignLeft
EditingCommands.AlignRight
EditingCommands.Backspace
EditingCommands.CorrectSpellingError
EditingCommands.DecreaseFontSize
EditingCommands.DecreaseIndentation
EditingCommands.Delete
EditingCommands.DeleteNextWord
EditingCommands.DeletePreviousWord
EditingCommands.EnterLineBreak
EditingCommands.EnterParagraphBreak
EditingCommands.IgnoreSpellingError
EditingCommands.IncreaseFontSize
EditingCommands.IncreaseIndentation
EditingCommands.MoveDownByLine
EditingCommands.MoveDownByPage
EditingCommands.MoveDownByParagraph
EditingCommands.MoveLeftByCharacter
EditingCommands.MoveLeftByWord
EditingCommands.MoveRightByCharacter
EditingCommands.MoveRightByWord
EditingCommands.MoveToDocumentEnd
EditingCommands.MoveToDocumentStart
EditingCommands.MoveToLineEnd
EditingCommands.MoveToLineStart
EditingCommands.MoveUpByLine
EditingCommands.MoveUpByPage
EditingCommands.MoveUpByParagraph
EditingCommands.SelectDownByLine
EditingCommands.SelectDownByPage
EditingCommands.SelectDownByParagraph
EditingCommands.SelectLeftByCharacter
EditingCommands.SelectLeftByWord
EditingCommands.SelectRightByCharacter
EditingCommands.SelectRightByWord
EditingCommands.SelectToDocumentEnd
EditingCommands.SelectToDocumentStart
EditingCommands.SelectToLineEnd
EditingCommands.SelectToLineStart
EditingCommands.SelectUpByLine
EditingCommands.SelectUpByPage
EditingCommands.SelectUpByParagraph
EditingCommands.TabBackward
EditingCommands.TabForward
EditingCommands.ToggleBold
EditingCommands.ToggleBullets
EditingCommands.ToggleInsert
EditingCommands.ToggleItalic
EditingCommands.ToggleNumbering
EditingCommands.ToggleSubscript
EditingCommands.ToggleSuperscript
EditingCommands.ToggleUnderline
MediaCommands.BoostBass
MediaCommands.ChannelDown
MediaCommands.ChannelUp
MediaCommands.DecreaseBass
MediaCommands.DecreaseMicrophoneVolume
MediaCommands.DecreaseTreble
MediaCommands.DecreaseVolume
MediaCommands.FastForward
MediaCommands.IncreaseBass
MediaCommands.IncreaseMicrophoneVolume
MediaCommands.IncreaseTreble
MediaCommands.IncreaseVolume
MediaCommands.MuteMicrophoneVolume
MediaCommands.MuteVolume
MediaCommands.NextTrack
MediaCommands.Pause
MediaCommands.Play
MediaCommands.PreviousTrack
MediaCommands.Record
MediaCommands.Rewind
MediaCommands.Select
MediaCommands.Stop
MediaCommands.ToggleMicrophoneOnOff
MediaCommands.TogglePlayPause
NavigationCommands.BrowseBack
NavigationCommands.BrowseForward
NavigationCommands.BrowseHome
NavigationCommands.BrowseStop
NavigationCommands.DecreaseZoom
NavigationCommands.Favorites
NavigationCommands.FirstPage
NavigationCommands.GoToPage
NavigationCommands.IncreaseZoom
NavigationCommands.LastPage
NavigationCommands.NavigateJournal
NavigationCommands.NextPage
NavigationCommands.PreviousPage
NavigationCommands.Refresh
NavigationCommands.Search
NavigationCommands.Zoom
Slider.DecreaseLarge
Slider.DecreaseSmall
Slider.IncreaseLarge
Slider.IncreaseSmall
Slider.MaximizeValue
Slider.MinimizeValue

This list is complete.

If there are any additional gestures in the themes, they can easily be extracted by loading the theme resource dictionary and doing some LINQ on it. The queries are trivial: Just search for <InputGesture>. Update: I don't think there are any gestures in the themes, since the default gestures are loaded from resources. So this part will probably not be necessary.

Upvotes: 90

Elangovan
Elangovan

Reputation:

Checkout this link http://en.csharp-online.net/WPF_Concepts%E2%80%94Built-In_Commands

WPF's built-in commands are exposed as static properties of five different classes:

    * ApplicationCommands—Close, Copy, Cut, Delete, Find, Help, New, Open, Paste, Print, PrintPreview, Properties, Redo, Replace, Save, SaveAs, SelectAll, Stop, Undo, and more 

    * ComponentCommands—MoveDown, MoveLeft, MoveRight, MoveUp, ScrollByLine, ScrollPageDown, ScrollPageLeft, ScrollPageRight, ScrollPageUp, SelectToEnd, SelectToHome, SelectToPageDown, SelectToPageUp, and more 

    * MediaCommands—ChannelDown, ChannelUp, DecreaseVolume, FastForward, IncreaseVolume, MuteVolume, NextTrack, Pause, Play, PreviousTrack, Record, Rewind, Select, Stop, and more 

    * NavigationCommands—BrowseBack, BrowseForward, BrowseHome, BrowseStop, Favorites, FirstPage, GoToPage, LastPage, NextPage, PreviousPage, Refresh, Search, Zoom, and more 

    * EditingCommands—AlignCenter, AlignJustify, AlignLeft, AlignRight, CorrectSpellingError, DecreaseFontSize, DecreaseIndentation, EnterLineBreak, EnterParagraphBreak, IgnoreSpellingError, IncreaseFontSize, IncreaseIndentation, MoveDownByLine, MoveDownByPage, MoveDownByParagraph, MoveLeftByCharacter, MoveLeftByWord, MoveRightByCharacter, MoveRightByWord, and more

Upvotes: 1

Drew Marsh
Drew Marsh

Reputation: 33379

Check out the ApplicationCommands, ComponentCommands and NavigationCommands classes. These classes all contain static properties representing various, standard routed commands which you can use within your own applications and to interact with intrinsic controls within the framework.

Upvotes: 8

Related Questions