在使用WPF的时候对int或者bool类型进行绑定出现InvalidCastException: T for DelegateCommand
<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