tro*_*ous 2 .net c# wpf command eventargs
看似简单的概念却无法超越这个.
我有一个命令... _Executed方法接收KeyValuePair(类型无关紧要),因为它是参数.
myCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
KeyValuePair<System.Type, MyCustomArgs> kvp = e.Parameter as KeyValuePair<Type, MyCustomArgs>;
:
:
:
}
Run Code Online (Sandbox Code Playgroud)
不能这样做,因为它不可空.我该如何做到这一点?我想从e.Parameter中提取KeyValuePair.
欣赏任何见解,并在必要时愉快地发布更多代码/信息.
您必须使用显式强制转换而不是隐式强制转换.
隐式演员:
KeyValuePair<System.Type, MyCustomArgs> kvp = e.Parameter as KeyValuePair<Type, MyCustomArgs>;
Run Code Online (Sandbox Code Playgroud)
明确的演员:
KeyValuePair<System.Type, MyCustomArgs> kvp = (KeyValuePair<System.Type, MyCustomArgs>)e.Parameter;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3606 次 |
最近记录: |