Missing EventToCommand behaviour in mvvmlight for Windows 8 - Work Around?

孤者浪人 提交于 2019-12-21 04:38:07

问题


Question says it all really :)

I'm writing a Windows 8 app in XAML/C# using MVVM Light and I've noticed the EventToCommand feature hasn't been implemented yet.

Are there any work arounds for this that anybody can suggest?

thanks!


回答1:


Check out the EventToCommand behavior written by LocalJoost which uses Reactive Extensions: http://dotnetbyexample.blogspot.be/2012/07/a-winrt-behavior-to-mimic-eventtocommand.html




回答2:


You can now accomplish what EventToCommand used to do using the Behaviors SDK (XAML) for Visual Studio 2013, without using other tools, (@localJoost 's WinRTBehaviors is deprecated now after it helped all of us those times) :

An example of its use would be as follows :

<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>

Where Interactivity and Core are referenced :

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



回答3:


I just did a blog post on that exact issue see my entry here.

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

Uses WinRTBehaviors and Win8nl from @localJoost



来源:https://stackoverflow.com/questions/12020559/missing-eventtocommand-behaviour-in-mvvmlight-for-windows-8-work-around

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!