我在 Windows Phone 8 项目中使用 GalaSoft - MVVM Light Toolkit 遇到了一个相当奇怪的问题。突然(在合并了一些东西之后)我所有的 EventToCommand 调用都不再工作了。他们以前工作过。我已经尝试删除 MvvmLight 工具包并使用 Nuget 再次引用它,但结果保持不变。
一个例子:
MainMenuPage.xaml
<phone:PhoneApplicationPage
...
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:commands="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8"
....>
<phone:PhoneApplicationPage.DataContext >
<Binding Source="{StaticResource MainMenuViewModel}"/>
</phone:PhoneApplicationPage.DataContext>
<!-- catch back key press -->
<i:Interaction.Triggers>
<i:EventTrigger EventName="BackKeyPress">
<commands:EventToCommand
Command="{Binding BackKeyPressCommand}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
MainMenuViewModel.cs
// back key press command
public RelayCommand<object> BackKeyPressCommand { get; set; }
public MainMenuViewModel()
{
BackKeyPressCommand = new RelayCommand<object>(
BackKeyPress,
(o) => true
);
...
}
private void BackKeyPress(Object o)
{
// handle back key press
}
这在以前非常有效,但现在 BackKeyPress(Object o) 方法不再被调用。所有 EventToComamnd 调用都会发生这种情况。
如果我删除 xmlns 标签,Resharper 建议添加:
xmlns:command="http://www.galasoft.ch/mvvmlight"
结果:
名称空间“ http://www.galasoft.ch/mvvmlight ”中不存在名称“EventToCommand ”
任何人都遇到过类似的问题或知道是什么原因造成的?