mvvmlight for Windows 8中缺少EventToCommand行为 - 如何解决?

6

问题已经说得很清楚了 :)

我正在使用MVVM Light在XAML/C#中编写Windows 8应用程序,我注意到EventToCommand功能尚未实现。

有人可以建议任何解决方法吗?

谢谢!

3个回答

14
现在你可以使用Visual Studio 2013的Behaviors SDK (XAML)来完成EventToCommand以前的功能,而无需使用其他工具,(@localJoost的WinRTBehaviors现已过时,尽管它曾经帮助我们所有人):

enter image description here

其使用示例如下:
<Slider x:Name="Sl_VolumeSilder">
        <Interactivity:Interaction.Behaviors>
            <Core:EventTriggerBehavior EventName="ValueChanged">
                <Core:InvokeCommandAction Command="{Binding OnSliderValueChangedCommand}" CommandParameter="{Binding ElementName=Sl_VolumeSilder, Path=Value}"/>
            </Core:EventTriggerBehavior>
        </Interactivity:Interaction.Behaviors>
</Slider>

引用 Interactivity 和 Core 的位置:

xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"

快速评论,这显然只适用于针对Windows 8.1的目标。VS 2013的要求暗示了这一点,但文档并不太清楚。 - htuomola
是的,这是正确的。由于VS2013只创建Windows8.1应用程序,但您仍然可以在VS2012中创建Windows8应用程序,并稍后在VS2013中打开它们。 - AymenDaoudi

4

谢谢!这个很好地完成了工作。 - lookitskris

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接