WPF Built-in Commands WPF Built-in Commands wpf wpf

WPF Built-in Commands


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.CancelPrintApplicationCommands.CloseApplicationCommands.ContextMenuApplicationCommands.CopyApplicationCommands.CorrectionListApplicationCommands.CutApplicationCommands.DeleteApplicationCommands.FindApplicationCommands.HelpApplicationCommands.NewApplicationCommands.NotACommandApplicationCommands.OpenApplicationCommands.PasteApplicationCommands.PrintApplicationCommands.PrintPreviewApplicationCommands.PropertiesApplicationCommands.RedoApplicationCommands.ReplaceApplicationCommands.SaveApplicationCommands.SaveAsApplicationCommands.SelectAllApplicationCommands.StopApplicationCommands.UndoComponentCommands.ExtendSelectionDownComponentCommands.ExtendSelectionLeftComponentCommands.ExtendSelectionRightComponentCommands.ExtendSelectionUpComponentCommands.MoveDownComponentCommands.MoveFocusBackComponentCommands.MoveFocusDownComponentCommands.MoveFocusForwardComponentCommands.MoveFocusPageDownComponentCommands.MoveFocusPageUpComponentCommands.MoveFocusUpComponentCommands.MoveLeftComponentCommands.MoveRightComponentCommands.MoveToEndComponentCommands.MoveToHomeComponentCommands.MoveToPageDownComponentCommands.MoveToPageUpComponentCommands.MoveUpComponentCommands.ScrollByLineComponentCommands.ScrollPageDownComponentCommands.ScrollPageLeftComponentCommands.ScrollPageRightComponentCommands.ScrollPageUpComponentCommands.SelectToEndComponentCommands.SelectToHomeComponentCommands.SelectToPageDownComponentCommands.SelectToPageUpDocumentViewer.FitToHeightCommandDocumentViewer.FitToMaxPagesAcrossCommandDocumentViewer.FitToWidthCommandDocumentViewer.ViewThumbnailsCommandEditingCommands.AlignCenterEditingCommands.AlignJustifyEditingCommands.AlignLeftEditingCommands.AlignRightEditingCommands.BackspaceEditingCommands.CorrectSpellingErrorEditingCommands.DecreaseFontSizeEditingCommands.DecreaseIndentationEditingCommands.DeleteEditingCommands.DeleteNextWordEditingCommands.DeletePreviousWordEditingCommands.EnterLineBreakEditingCommands.EnterParagraphBreakEditingCommands.IgnoreSpellingErrorEditingCommands.IncreaseFontSizeEditingCommands.IncreaseIndentationEditingCommands.MoveDownByLineEditingCommands.MoveDownByPageEditingCommands.MoveDownByParagraphEditingCommands.MoveLeftByCharacterEditingCommands.MoveLeftByWordEditingCommands.MoveRightByCharacterEditingCommands.MoveRightByWordEditingCommands.MoveToDocumentEndEditingCommands.MoveToDocumentStartEditingCommands.MoveToLineEndEditingCommands.MoveToLineStartEditingCommands.MoveUpByLineEditingCommands.MoveUpByPageEditingCommands.MoveUpByParagraphEditingCommands.SelectDownByLineEditingCommands.SelectDownByPageEditingCommands.SelectDownByParagraphEditingCommands.SelectLeftByCharacterEditingCommands.SelectLeftByWordEditingCommands.SelectRightByCharacterEditingCommands.SelectRightByWordEditingCommands.SelectToDocumentEndEditingCommands.SelectToDocumentStartEditingCommands.SelectToLineEndEditingCommands.SelectToLineStartEditingCommands.SelectUpByLineEditingCommands.SelectUpByPageEditingCommands.SelectUpByParagraphEditingCommands.TabBackwardEditingCommands.TabForwardEditingCommands.ToggleBoldEditingCommands.ToggleBulletsEditingCommands.ToggleInsertEditingCommands.ToggleItalicEditingCommands.ToggleNumberingEditingCommands.ToggleSubscriptEditingCommands.ToggleSuperscriptEditingCommands.ToggleUnderlineMediaCommands.BoostBassMediaCommands.ChannelDownMediaCommands.ChannelUpMediaCommands.DecreaseBassMediaCommands.DecreaseMicrophoneVolumeMediaCommands.DecreaseTrebleMediaCommands.DecreaseVolumeMediaCommands.FastForwardMediaCommands.IncreaseBassMediaCommands.IncreaseMicrophoneVolumeMediaCommands.IncreaseTrebleMediaCommands.IncreaseVolumeMediaCommands.MuteMicrophoneVolumeMediaCommands.MuteVolumeMediaCommands.NextTrackMediaCommands.PauseMediaCommands.PlayMediaCommands.PreviousTrackMediaCommands.RecordMediaCommands.RewindMediaCommands.SelectMediaCommands.StopMediaCommands.ToggleMicrophoneOnOffMediaCommands.TogglePlayPauseNavigationCommands.BrowseBackNavigationCommands.BrowseForwardNavigationCommands.BrowseHomeNavigationCommands.BrowseStopNavigationCommands.DecreaseZoomNavigationCommands.FavoritesNavigationCommands.FirstPageNavigationCommands.GoToPageNavigationCommands.IncreaseZoomNavigationCommands.LastPageNavigationCommands.NavigateJournalNavigationCommands.NextPageNavigationCommands.PreviousPageNavigationCommands.RefreshNavigationCommands.SearchNavigationCommands.ZoomSlider.DecreaseLargeSlider.DecreaseSmallSlider.IncreaseLargeSlider.IncreaseSmallSlider.MaximizeValueSlider.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.


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.


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