首页新闻找找看学习计划

MVVM模式下使用Prism的 DelegateCommand<T>为何会错误提示“T不是对象或者为空”?

0
[待解决问题]

Xaml里如下:

<ComboBox x:Name="comboType" Grid.Column="1" Grid.Row="4" HorizontalAlignment="Left" VerticalAlignment="Center" Width="150" Text="{Binding Question.Type}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SetTypeCommand}" CommandParameter="{Binding SelectedIndex,ElementName=comboType}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBoxItem Content="设置题型..."></ComboBoxItem>
<ComboBoxItem Content="单选题"></ComboBoxItem>
<ComboBoxItem Content="多选题"></ComboBoxItem>

</ComboBox>

 

viewModel里如下:

private DelegateCommand<int> _setTypeCommand; 
public DelegateCommand<int> SetTypeCommand
{
get { return _setTypeCommand??(_setTypeCommand = new DelegateCommand<int>(SetType)); }
set { _setTypeCommand = value; }
}

private void SetType(int selectedIndex)
{
//
}

 

运行时就提示错误:T for DelegateCommand<T> is not an object nor Nullable。

试了下,如果这个T为string的话就不会出错,但为 int的话就报错,请问为什么?该怎么解决?谢谢!

WPF
仁兄的主页 仁兄 | 菜鸟二级 | 园豆:202
提问于:2017-12-08 16:51
< >
分享
所有回答(1)
0

改用 

int?
OpportunityLiu | 园豆:255 (菜鸟二级) | 2017-12-09 01:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册