我想用下面的XAML如何定義這本詞典在Silverlight XAML
Dictionary<Tuple<ModifierKeys, Key>, ICommand>
我知道我需要創建繼承IDitionary,BYT如何調用它或使用它withtin的XAML
類定義Dictionry在用戶控件的水平,我想創造shortcutlist,傳遞給全球行爲趕上的keydown在MVVM模型,所以我想通過這本詞典的行爲要檢查
我想用下面的XAML如何定義這本詞典在Silverlight XAML
Dictionary<Tuple<ModifierKeys, Key>, ICommand>
我知道我需要創建繼承IDitionary,BYT如何調用它或使用它withtin的XAML
類定義Dictionry在用戶控件的水平,我想創造shortcutlist,傳遞給全球行爲趕上的keydown在MVVM模型,所以我想通過這本詞典的行爲要檢查
如果您的XAML支持它(我不是Silverlight的專家)可以使用x:xaml中的TypeArguments。
看到這個鏈接http://msdn.microsoft.com/en-us/library/ms750476(v=vs.100).aspx欲瞭解更多信息。
如果您的XAML不支持的話,一個很簡單的方法來實現這一目標是創建自己的類,將繼承dictionnary你想要的類型參數:
public class YourTuple
{
public ModifierKeys ModifierKey { get; set; }
public ICommand Command { get; set; }
}
public class YourClass : Dictionary<YourTuple, ICommand>
,然後直接使用它您的xaml
<Window x:Class="SO.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:SO="clr-namespace:SO"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<SO:YourClass>
<YourCommand ...>
<YourCommand.Key>
<YourTuple ModifierKey="..." Key="..."
</YourCommand.Key>
</YourCommand>
...
</SO:YourClass>
</Window.Resources>
</Window>
我可以在這裏填寫 – AMH
您能否提供更多關於您想要實現的細節?這將幫助您獲得更好的答案。很可能有更好的方式去做,但沒有上下文,任何人都無法建議。 – ChrisF
我做過了,請檢查 – AMH