[英]How can I bind a Hold/DoubleTap event of a button to a property in ViewModel
I have a view containing a button. 我有一个包含按钮的视图。 And i want to perform an action on Hold event.
我想在Hold事件上执行操作。 How can i do this in mvvm?
我如何在mvvm中做到这一点? For Tap event i can Bind it to a Command property.
对于Tap事件,我可以将其绑定到Command属性。 Is it possible to do this with same way?
是否可以用相同的方式做到这一点?
不知道它是否支持该命令,否则,您可以使用MVVM Light Toolkit(免费和开源)行为:EventToCommand
I would go with Braulio's answer - MVVM Light is what I would use, but back in the Silverlight 3 days I used custom attached properties to achieve this. 我会使用Braulio的答案-MVVM Light是我要使用的,但是回到Silverlight 3天后,我使用自定义附加属性来实现这一目标。 See here for an example of custom attached properties: http://umairsaeed.com/2010/04/22/custom-attached-properties-in-silverlight/
有关自定义附加属性的示例,请参见此处: http : //umairsaeed.com/2010/04/22/custom-attached-properties-in-silverlight/
You could create a custom attached property for the hold event to bind the command to and then use it like so: 您可以为hold事件创建一个自定义附加属性,将命令绑定到该属性,然后像这样使用它:
<Border local:MyTextBoxControl.HoldEventCommand="{Binding HoldCommand}"/>
This is a lot of work compared with including the mvvm light toolkit in your project and then doing this: 与在项目中包含mvvm light工具箱然后执行以下操作相比,这需要大量工作:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Hold">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding YourCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.