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:
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);
}
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?
First, you want to set style for your control, say a button, as in the question:
Next, set the property in your VM:
And don't forget the converter.
Btw, if you want an easy trick, when on your control on the XAML file, right click it, and in the menu go to, 'Edit Style' . I then go to 'Edit Copy' and it gives me everything I need. You can edit the style directly in your Resource Dictionary.
I personally prefer to use
EventToCommand
because of thePassEventArgsToCommand
property:Which you then use like this:
In practice it's not quite as important with mouse messages because I usually substitute the parameters with a proxy that, in addition to other things, allows my view model to raise capture/release events etc. It is handy though for things like keystrokes or the Closing event etc where you need to get at the args and using a proxy is just adding another unnecessary layer of abstraction.
You can use interractions
declare namespace
than you can bind command to event