.net wpf command

.net - Comandos incorporados de WPF



command (3)

Consulte este enlace here

Los comandos incorporados de WPF se exponen como propiedades estáticas de cinco clases diferentes:

* 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

Estoy buscando una lista completa de comandos incorporados de WPF.

La mejor lista que he encontrado hasta ahora está here , pero no muestra todos los comandos.

Algunos detalles agradables serían:

  • Controles / componentes compatibles con los comandos (por ejemplo, TextBox admite comandos de edición como Pegar, Copiar, Cortar, Rehacer y Deshacer);

  • Los gestos de teclas predeterminados y el texto de la interfaz de usuario (se pueden extraer de MSDN Library ).


Echa un vistazo a las clases ApplicationCommands , ComponentCommands y NavigationCommands . Todas estas clases contienen propiedades estáticas que representan diversos comandos enrutados estándar que puede utilizar dentro de sus propias aplicaciones e interactuar con controles intrínsecos dentro del marco.


Es fácil mostrar una lista completa de todos los comandos en todos los ensamblados cargados:

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

Con PresentationFramework cargado, obtengo la lista al final de esta respuesta, que verá que está absolutamente completa.

Si también desea ver el tipo de comando (por ejemplo, RoutedUIComand) y los gestos, puede agregar esto a LINQ:

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

Entonces su selección podría ser algo como esto:

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

También es posible descubrir mediante programación qué controles hacen algo con un comando dado. Básicamente, algo como esto debería funcionar (no se ha intentado, pero esto te dará una 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();

donde ConvertILToString probablemente sería algo como esto:

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

Los resultados se pueden usar de la forma que desee, por ejemplo, se pueden mostrar utilizando un control de artículos:

<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 ...

Alternativamente, puede generar los datos en formato de texto o XML o agregarlos a una base de datos. También tenga en cuenta que esta segunda consulta se puede activar con la iteración del comando en el exterior si prefiere una lista por comando.

El código anterior le dará los hechos precisos y no mentirá, porque está mirando el NET Framework en sí.

Aquí está la lista prometida de todos los comandos en 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

Esta lista está completa.

Si hay gestos adicionales en los temas, se pueden extraer fácilmente cargando el diccionario de recursos del tema y haciendo algo de LINQ en él. Las consultas son triviales: simplemente busque <InputGesture> . Actualización: no creo que haya ningún gesto en los temas, ya que los gestos predeterminados se cargan desde los recursos. Así que esta parte probablemente no será necesaria.