gpt4 book ai didi

c# - 如何将作为参数传递的 KeyValuePair 转换为 Command_Executed?

转载 作者:行者123 更新时间:2023-11-30 20:04:45 25 4
gpt4 key购买 nike

看似简单的概念,却过不去。

我有一个命令..._Executed 方法接收一个 KeyValuePair(类型无关紧要)作为参数。

myCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
KeyValuePair<System.Type, MyCustomArgs> kvp = e.Parameter as KeyValuePair<Type, MyCustomArgs>;
:
:
:
}

不能这样做,因为它不可为空。我该如何做到这一点?我想从 e.Parameter 中提取 KeyValuePair。

感谢任何见解,如有必要,将很乐意发布更多代码/信息。

最佳答案

您必须使用显式转换,而不是像您所做的那样使用隐式转换。
隐式转换:

KeyValuePair<System.Type, MyCustomArgs> kvp = e.Parameter as KeyValuePair<Type, MyCustomArgs>; 

显式转换:

KeyValuePair<System.Type, MyCustomArgs> kvp = (KeyValuePair<System.Type, MyCustomArgs>)e.Parameter; 

关于c# - 如何将作为参数传递的 KeyValuePair 转换为 Command_Executed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12487276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com