如何在MVVM中制作MouseOver事件? [英] How to make MouseOver event in MVVM?

查看:66
本文介绍了如何在MVVM中制作MouseOver事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在单击按钮时进行导航:

I use the following code to navigate on button click:

XAML:

<Button x:Name ="Btn_Import" Grid.Row="33" Grid.Column="15" Grid.ColumnSpan="36" Grid.RowSpan="36" Command="{Binding NavigateCommand}"  CommandParameter="ViewImportProgress"/>

ViewModel:

ViewModel:

public DelegateCommand<string> NavigateCommand { get; set; }

public MainButtonsViewModel(IRegionManager regionManager, IMainMenuTooltipViewer mainMenuTooltipViewer)
        {
            NavigateCommand = new DelegateCommand<string>(Navigate); 
        }

 private void Navigate(string uri)
        {
            regionManager.RequestNavigate("ScreenNavigationRegion", uri); 


        }

,效果很好.现在我的问题是,使导航在MouseOver事件而不是MouseClick事件上工作的等效代码是什么,当然是在MVVM模式下并使用Prism?

and it works fine. Now my question is what would be equivalent code to make navigation work on MouseOver event instead of MouseClick event, of course in MVVM pattern and using Prism?

推荐答案

您可以使用互动方式

声明名称空间

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

比您可以将命令绑定到事件

than you can bind command to event

<Button Content="Navigate" >

    <i:Interaction.Triggers>

        <i:EventTrigger EventName="MouseEnter">

            <i:InvokeCommandAction Command="{Binding NavigateCommand}"   CommandParameter="ViewImportProgress"/>

        </i:EventTrigger>

    </i:Interaction.Triggers>

</Button>

这篇关于如何在MVVM中制作MouseOver事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆