|
I have been struggling with EventToCommand and MouseMove. I have tried binding to my ViewModel and to my View, but nothing fires. Please help..
I am working with Silverlight 4, NOT WPF. I think I saw somewhere that EventToCommand does not work with Silverlight except for the Load event. Bbut for the life of me I can not find that post again.
I have pasted my code and XAML below for your review. Thanks!
Public Shared ReadOnly MouseMoveCommandProperty As DependencyProperty = DependencyProperty.Register("MouseMoveCommand", GetType(RelayCommand(Of MouseEventArgs)), GetType(MyViewModel), Nothing)
Public Property MouseMoveCommand As RelayCommand(Of MouseEventArgs)
Get
If GetValue(MouseMoveCommandProperty) Is Nothing Then
Return New RelayCommand(Of MouseEventArgs)(Sub(e) MyMouseMove(e))
Else
Return DirectCast(GetValue(MouseMoveCommandProperty), RelayCommand(Of MouseEventArgs))
End If
End Get
Set(ByVal value As RelayCommand(Of MouseEventArgs))
Me.SetValue(MouseMoveCommandProperty, value)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(MethodBase.GetCurrentMethod().Name.Substring(4)))
End Set
End Property
Public Sub MyMouseMove(e As MouseEventArgs)
Dim p As Point = e.GetPosition(e.OriginalSource)
End Sub
<Canvas x:Name="MyCanvas" Cursor="{Binding ActionType, Source={StaticResource MyVM}, Mode=OneWay, Converter={StaticResource ActionToCursor}}" MouseLeftButtonDown="Canvas_MouseLeftButtonDown" MouseLeftButtonUp="Canvas_MouseLeftButtonUp">
<i:Interaction.Triggers> <i:EventTrigger> <cmd:EventToCommand Command="{Binding MouseMoveCommand, Source={StaticResource MyVM}}" PassEventArgsToCommand="True"/> </i:EventTrigger> </i:Interaction.Triggers> </Canvas>
|