天猫网站设计特点,html5做服装网站,多少钱的英文怎么写,小程序在线制作模板WPF的有些UI元素有Command属性可以直接实现绑定#xff0c;如Button 但是很多Event的触发如何绑定到ViewModel中的Command呢#xff1f; 答案就是使用EventTrigger可以实现。 继续上一篇对Slider的研究#xff0c;在View中修改Interaction. i:Interaction.Triggers如Button 但是很多Event的触发如何绑定到ViewModel中的Command呢 答案就是使用EventTrigger可以实现。 继续上一篇对Slider的研究在View中修改Interaction. i:Interaction.Triggersi:EventTrigger EventNameValueChangedi:InvokeCommandAction Command{Binding ValueChangedCommand} //i:EventTrigger/i:Interaction.Triggers 那么如果将EventName修改为Thumb.DragCompleted 后发现这个事件并不会被触发原因是Because the command is hooked up to the Slider, but the event is fired on the Thumb。 参考http://stackoverflow.com/questions/14331272/issue-with-thumb-dragstarted-event-with-mvvmlight 参考上述链接中Tom Allen的方法后可以实现, 但是这个方法并没有很好的遵守MVVM模式。 于是接着研究既然DragCompleted是挂在Thumb上面的那么为何不直接和Thumb 绑定呢 修改Slider的ControlTemplate, 在Track控件中的Thumb中绑定Event 成功 UserControl.ResourcesControlTemplate x:KeytrackThumb TargetType{x:Type Slider}Border Background{TemplateBinding Background}BorderBrush{TemplateBinding BorderBrush}BorderThickness{TemplateBinding BorderThickness}GridTrack x:NamePART_TrackTrack.ThumbThumb Width10i:Interaction.Triggersi:EventTrigger EventNameDragCompletedi:InvokeCommandAction Command{Binding ValueChangedCommand} //i:EventTrigger/i:Interaction.Triggers/Thumb/Track.Thumb/Track/Grid/Border/ControlTemplate/UserControl.Resources 参考 http://social.technet.microsoft.com/wiki/contents/articles/18199.event-handling-in-an-mvvm-wpf-application.aspx http://www.codeproject.com/Articles/274982/Commands-in-MVVM#example9转载于:https://www.cnblogs.com/DreamRecorder/p/9849986.html