我正在查找內置WPF命令的完整列表。WPF內置命令
到目前爲止我發現的最好名單是here,但它沒有列出所有的命令。
一些可有可無具有細節將是:
控制/與所述命令的支持組件(例如,TextBox支持編輯命令,如粘貼,複製,剪切,重做,和撤消) ;
默認鍵手勢和UI文本(可從MSDN Library中提取)。
我正在查找內置WPF命令的完整列表。WPF內置命令
到目前爲止我發現的最好名單是here,但它沒有列出所有的命令。
一些可有可無具有細節將是:
控制/與所述命令的支持組件(例如,TextBox支持編輯命令,如粘貼,複製,剪切,重做,和撤消) ;
默認鍵手勢和UI文本(可從MSDN Library中提取)。
這是很容易顯示在所有加載的程序集的所有命令的完整列表:
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();
}
隨着PresentationFramework的加載,我得到這個答案的底部列表,你會看到它是絕對完整的。這樣
let commandType = prop.PropertyType
let gestures =
typeof(UIElement).IsAssignableFrom(commandType) ?
((UIElement)prop.GetValue(null)).InputGestures :
null
那麼你的選擇可能是這樣:
如果您還希望看到命令類型(例如RoutedUIComand)和手勢,你可以添加這對LINQ
select type.Name + "." + prop.Name + " " + commandType.Name + " " + gestures
以編程方式查找哪些控件對給定命令執行某些操作也是可能的。基本上,這樣的事情應該工作(沒試過,但是這會給你的想法):
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();
其中ConvertILToString很可能是這樣的:
static string ConvertILToString(byte[] bytes)
{
return new string(bytes.Where(b => b!=0).Select(b => (char)b).ToArray());
}
結果可以使用任何方式你喜歡,例如他們可以使用一個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 ...
另外,您可以輸出文本或XML格式的數據或將其添加到數據庫。另外請注意,如果您更喜歡使用列表命令,則可以使用外部的命令迭代轉換此第二個查詢。
上面的代碼會給你確切的事實,不會撒謊,因爲它正在看着.NET Framework本身。
這裏是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
這個列表是完整的。
如果在主題中有任何額外的手勢,可以通過加載主題資源字典並對其進行一些LINQ來輕鬆提取它們。查詢很簡單:只需搜索<InputGesture>
。 更新:我不認爲主題中有任何手勢,因爲默認手勢是從資源中加載的。所以這部分可能不是必需的。
退房的ApplicationCommands,ComponentCommands和NavigationCommands類。這些類都包含表示各種標準路由命令的靜態屬性,您可以在自己的應用程序中使用這些命令,並與框架內的內部控件進行交互。
結帳這個鏈接http://en.csharp-online.net/WPF_Concepts%E2%80%94Built-In_Commands
WPF的內置命令被公開爲五種不同類別的靜態屬性:
* 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
這就是我提出的問題。無論如何感謝您的回覆。 – jpbochi
男人,我認爲這是迄今爲止最好的答案。我會在本週末嘗試* classesReferencingCommand *查詢。有一段時間,我會繼續提問,看看是否還有其他事情發生,但我想你會得到公認的答案。謝謝! – jpbochi