Intellisense 不适用于 MVVM 轻型工具包 [英] Intellisense doesn't work for MVVM light toolkit
问题描述
我昨天开始使用 MVVM 模式.但是为了处理事件,我需要安装 MVVM 轻型工具包.我这样做了,并将库添加到引用中.在 UserControl 我宣布了该库,但是当我想使用任何工具包时写它不显示任何建议,不接受我想写的内容并显示此错误无法将类型为 'EventToCommand' 的值添加到类型为 'TriggerActionCollection' 的集合或字典中"
I began to use MVVM pattern yesterday.But for working with events i needed to install MVVM light toolkit.I did that,and added library to references.At UserControl i announced that library,but when i want to use toolkit whatever i write it doesnt show any suggestions and doesnt accept what i want to write and shows this error "A value of type 'EventToCommand' cannot be added to a collection or dictionary of type 'TriggerActionCollection' "
<EventTrigger RoutedEvent="TextChanged">
<mvvm:EventToCommand Command="{Binding Test}"/>
</EventTrigger>
`
推荐答案
你必须这样使用它..
You have to use it like this ..
要添加的命名空间:xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<mvvm:EventToCommand Command="{Binding Path=UserControlLoadedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
不要忘记在您的项目中添加对 System.Windows.Interactivity
的引用
Dont forget to add a reference to System.Windows.Interactivity
to your project
您需要在
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<mvvm:EventToCommand Command="{Binding Path=UserControlLoadedCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
然后你可以在 ViewModel ..... 你可能需要使用 Generic RelayCommand
作为
And then you can get that at ViewModel ..... you Might Need to use Generic RelayCommand
as
RelayCommand<KeyEventArgs> myCommand= new RelayCommand<KeyEventArgs>(Execute,CanExecute)
这篇关于Intellisense 不适用于 MVVM 轻型工具包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!