I am trying to implement a Button in a WPF project, which sets a variable to 1 by clicking and back by releasing the button. Since I found no way to bind to MouseDown and MouseUp directly. I am trying to go with MVVM Light Toolkit, but it is not working. Does anyone know to handle this? VS2013 WPF4.5
My DLLs from MvvmLightLibs.4.2.30.0:
GalaSoft.MvvmLight.Extras.WPF45
GalaSoft.MvvmLight.WPF45
System.Windows.Interactivity
My XAML:
<UserControl x:Class="PMWA.View.OperatorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF45">
<Grid>
<Button x:Name="MoveUp"
Content="Up"
Margin="5">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<cmd:EventToCommand Command="{Binding MoveUpCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseUp">
<cmd:EventToCommand Command="{Binding StopMoveCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button x:Name="MoveDown"
Content="Down"
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<cmd:EventToCommand Command="{Binding MoveDownCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseUp">
<cmd:EventToCommand Command="{Binding StopMoveCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button x:Name="Apply"
Content="Apply"
Command="{Binding ApplyDistanceCommand}"
<TextBox x:Name="Distance"
Text="{Binding CurrentDistance}"
</Grid>
</UserControl>
Hier is my ViewModel:
private ICommand moveUpCommand;
public ICommand MoveUpCommand
{
get
{
if (moveUpCommand == null)
{
moveUpCommand = new RelayCommand(p => ExecuteMoveUpCommand());
}
return moveUpCommand;
}
}
private void ExecuteMoveUpCommand()
{
Trace.WriteLine("Move Up");
SetPort1(1);
}
And the binding is set up in MainWindow.xaml.cs like this:
private void SetupBindings()
{
var operatorModel = new Model.Operator();
operatorView.DataContext = new OperatorViewModel(operatorModel, measurementWeightListViewModel);
}
I have i third button which works fine but those up and down buttons wont do anything :(
I messed up in this thread, so i posted it here:
MVVM Light Toolkit EventTrigger binding doesnt work[
^]