首页 > 其他分享 >记录一次WPF命令参数报错,InvalidCastException: T for DelegateCommand<T> is not an object nor Nullable.

记录一次WPF命令参数报错,InvalidCastException: T for DelegateCommand<T> is not an object nor Nullable.

时间:2024-03-06 12:33:24浏览次数:358  
标签:DelegateCommand Nullable object OpenCommand InvalidCastException 报错 WPF

在使用WPF的时候对int或者bool类型进行绑定出现InvalidCastException: T for DelegateCommand is not an object nor Nullable.

 <Button Width="200" Height="30" Content="按钮" Command="{Binding OpenCommand}" CommandParameter="{Binding Msg}"/>
 
  OpenCommand = new DelegateCommand<int/bool>(ExecuteOpen);

解决方案如下:
1、加上非空? ,以下是int类型写法

 OpenCommand = new DelegateCommand<int?>(ExecuteOpen);

2、使用Nullable+泛型,下面是bool类型写法

 OpenCommand = new DelegateCommand<Nullable<bool>>(ExecuteOpen);

标签:DelegateCommand,Nullable,object,OpenCommand,InvalidCastException,报错,WPF
From: https://www.cnblogs.com/guchen33/p/18056271

相关文章

  • 2024-03-05 NestJs学习日志之新建nest项目,运行启动命令nest start报错:Could not find
    如题,低级错误。具体报错:CouldnotfindTypeScriptconfigurationfile"tsconfig.json".Please,ensurethatyouarerunningthiscommandintheappropriatedirectory(insideNestworkspace)找不到TypeScript配置文件“tsconfig.json”。请确保您在适当的目录(Nest工作......
  • mysql报错代码汇总
    先给大家看几个实例的错误分析与解决方案。1.ERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/data/mysql/mysql.sock'问题分析:可能是数据库没有启动或者是端口被防火墙禁止。解决方法:启动数据库或者防火墙开放数据库监听端口。2.ERROR1045......
  • Oceanbase数据库创建分区时报错
    报错信息:ERROR1044(42000):Accessdeniedforuser'root'@'%'todatabase'oceanbase'报错原因:由于OceanBase数据库中,oceanbase库是系统库,里面存放的是系统的很多表,所以不能进行操作,换个库即可,一般到test库下,执行操作......
  • mysql报错:SQL 错误 [1030] [HY000]: Got error 100 - 'InnoDB error' from storage en
    在mysql中进行alter时,报错:SQL错误[1030][HY000]:Goterror100-'InnoDBerror'fromstorageengine 原因:在配置my.cnf或my.ini里面innodb_force_recovery参数的值大于0,它默认值为0,如果大于0,innodb就会禁用insert、update、delete、alter语句。解决方式:在配置my.cn......
  • 未完成编辑 Linux CentOS7.6使用腾讯Yum源安装MySQL5.7,执行mysql-secure-installation
    学习安装MySQL时发现官方源很慢,试了国内腾讯源快,记录一下LinuxCentOS7.6前置环境:CPU1内存4GB硬盘SCSI20GB网络模式桥接系统内为自动DHCPpingqq.com可通互联网以下为MySQL5.7安装步骤编辑新repo库路径:/etc/yum.repos.d/mysql-community.repovi/etc/yum.repos......
  • mssql排序order by42000报错解决
    原文链接:https://blog.csdn.net/wang1qqqq/article/details/122961882在mssql查询中,如果子查询中使用orderby,会出现报错:[42000][Microsoft][ODBCDriver17forSQLServer][SQLServer]除非另外还指定了TOP、OFFSET或FORXML,否则,ORDERBY子句在视图、内联函数、派生表、子......
  • SQL报错:order by不能直接出现在union的子句中
    原文链接:https://www.cnblogs.com/xuwinwin/p/15877703.html1、报错写法:SELECT*FROMt1ORDERBYmonthASCUNIONSELECT*FROMt2ORDERBYmonthASC2、原因与解决办法:orderby不能直接出现在union的子句中,但是可以出现在子句的子句中。可以通过两个查询分别加括号......
  • PostgreSQL 在使用连表语句时报错 ERROR: operator does not exist: bigint = charact
    背景在使用PostgreSQL数据库过程中,使用了连表语句如下所示,其中a表的order_no为bigint类型,b表的order_no为varchar类型select*fromtable_orderainnerjointable_order_itembona.order_no=b.order_no;遇到提示:ERROR:operatordoesnotexist:bigint=characterv......
  • vite+vue3 遇到报错 Uncaught SyntaxError: Cannot use import statement outside a m
    按照报错找到了对应的位置import{createApp}from'/node_modules/.vite/deps/vue.js?v=d0a669cf'importAppfrom'/src/pages/project1/App.vue'//import'./index.css'//importrouterfrom"./router"//createApp(App).mount(&#......
  • 关于SAP-APP机器-R3trans -d报错-R3trans: /lib64/libstdc++.so.6: version `GLIBCXX_
    在SAP-应用-APP-机器上执行如下命令报错awpxxx03:prdadm270>R3trans-dR3trans:/lib64/libstdc++.so.6:version`GLIBCXX_3.4.26'notfound(requiredbyR3trans) 其实之前,使用过一种方法解决这个问题,可以参考笔者另一篇文章《关于Redhat-Linux中-compat-sap-c++的说......