【问题标题】:Missing EventToCommand behaviour in mvvmlight for Windows 8 - Work Around?Windows 8 的 mvvmlight 中缺少 EventToCommand 行为 - 解决方法?
【发布时间】:2012-08-18 17:09:43
【问题描述】:

问题说明了一切:)

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

有没有人可以建议的解决方法?

谢谢!

【问题讨论】:

    标签: c# windows-8 mvvm-light winrt-xaml


    【解决方案1】:

    您现在可以使用 Behaviors SDK (XAML) for Visual Studio 2013 完成 EventToCommand 过去所做的事情,而无需使用其他工具(@localJoost 的 WinRTBehaviors 在帮助我们所有人之后现在已被弃用):

    它的使用示例如下:

    <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 的要求暗示了这一点,但文档不太清楚。
    • 是的,因为VS2013只创建Windows8.1应用程序,您仍然可以在VS2012中创建Windows8应用程序,然后在VS2013中打开它们
    【解决方案2】:

    查看使用响应式扩展的 LocalJoost 编写的 EventToCommand 行为: http://dotnetbyexample.blogspot.be/2012/07/a-winrt-behavior-to-mimic-eventtocommand.html

    【讨论】:

    • 谢谢!这做得很好
    【解决方案3】:

    我刚刚就该问题发表了一篇博文,请在此处查看我的条目。

    http://blog.tattoocoder.com/2012/08/getting-started-w-windows-8-mvvm-light.html

    使用来自@localJoost 的 WinRTBehaviors 和 Win8nl

    【讨论】:

      猜你喜欢
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 2011-05-07
      相关资源
      最近更新 更多