I have a WPF application with Caliburn.Micro.
I want to handle slider’s move, i.e. MouseUp event.
<Slider cal:Message.Attach="[Event MouseUp] = [Action OnSliderMouseUp($this)]"
Value="{Binding PlayerPosition, Mode=OneWay}" MinWidth="200"
VerticalAlignment="Center" Minimum="0"
Maximum="{Binding Player.NaturalDuration.TimeSpan.TotalMilliseconds}"/>
In ViewModel:
public void OnSliderMouseUp(Slider slider)
{
int blah = 9;
}
OnSliderMouseUp() is never called. Could you please tell what I am missing?
Actually you have two problems:
The
Slidercontrol does not fires theMouseUpevent. If you interested in an event which fires when the user stops dragging the slider you are looking for the Thumb.DragCompleted.You can find more info here: WPF: Slider with an event that triggers after a user drags
But if you whould write
it still won’t work. Because Caliburn.Micro (to be preciese
System.Windows.Interactiviy.EventTriggerwhich is used by Calibrun.Micro) does not support attached events. For more info and a workaround see: using attached events with caliburn micro Message.AttachSo a working soultion (with the
RoutedEventTriggerimplementation from the above mentioned question):Note that because
Thumb.DragCompletedan attached event$thiswon’t work and you need to use $source instead.