大佬教程收集整理的这篇文章主要介绍了Mvvm-Light Silverlight,使用EventToCommand和Combobox,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<ComboBox Width="422" Height="24" DisplaymemberPath="Name" Itemssource="{Binding CategoryTypes}" SELEctedItem="{Binding SELEctedCategory}" > <i:Interaction.triggers> <i:Eventtrigger EventName="SELEctionChanged"> <MvvmLight:EventToCommand Command="{Binding SELEctCategoryCommand,Mode=TwoWay}" CommandParameter="{Binding SELEctedCategory,Mode=TwoWay}" MustToggleIsEnabledValue="True" /> </i:Eventtrigger> </i:Interaction.triggers> </ComboBox>
在我看来,
public ICommand SELEctCategoryCommand { get { return new SELEctCategoryCommand(this); } } public CategoryType SELEctedCategory { get; set; }
和ICommand
public class SELEctCategoryCommand : ICommand { private Rowviewmodel _rowviewmodel; public SELEctCategoryCommand(Rowviewmodel rowviewmodel) { _rowviewmodel = rowviewmodel; } public bool CanExecute(object parameter) { return true; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { CategoryType categoryType = (CategoryTypE) parameter; } }
但是,ICommand的Execute方法中的参数始终为空.我对SilverLight没有经验,所以我觉得我真的很想念这里的东西.谁能帮忙?提前致谢!
只要设置PassEventArgsToCommand =“True”
<ComboBox Width="422" Height="24" DisplaymemberPath="Name" Itemssource="{Binding CategoryTypes}" SELEctedItem="{Binding SELEctedCategory}"> <i:Interaction.triggers> <i:Eventtrigger EventName="SELEctionChanged"> <MvvmLight:EventToCommand Command="{Binding SELEctCategoryCommand,Mode=TwoWay}" MustToggleIsEnabledValue="True" PassEventArgsToCommand="True"/> </i:Eventtrigger> </i:Interaction.triggers> </ComboBox>
然后在Execute方法中执行以下操作:
public void Execute(object parameter) { SELEctionChangedEventArgs e = (SELEctionChangedEventArgs)parameter; CategoryType categoryType = (CategoryTypE)e.AddedItems[0]; }
以上是大佬教程为你收集整理的Mvvm-Light Silverlight,使用EventToCommand和Combobox全部内容,希望文章能够帮你解决Mvvm-Light Silverlight,使用EventToCommand和Combobox所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。