Reputation: 5375
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?
Upvotes: 3
Views: 3132
Reputation: 139758
Actually you have two problems:
The Slider
control does not fires the MouseUp
event. 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
<Slider cal:Message.Attach="[Event Thumb.DragCompleted] = [Action OnSliderMouseUp($this)]" />
it still won't work. Because Caliburn.Micro (to be preciese System.Windows.Interactiviy.EventTrigger
which is used by Calibrun.Micro) does not support attached events. For more info and a workaround see: using attached events with caliburn micro Message.Attach
So a working soultion (with the RoutedEventTrigger
implementation from the above mentioned question):
<Slider Value="{Binding PlayerPosition, Mode=OneWay}" MinWidth="200" ...>
<i:Interaction.Triggers>
<local:RoutedEventTrigger RoutedEvent="Thumb.DragCompleted">
<cal:ActionMessage MethodName="OnSliderMouseUp">
<cal:Parameter Value="$source" />
</cal:ActionMessage>
</local:RoutedEventTrigger>
</i:Interaction.Triggers>
</Slider>
Note that because Thumb.DragCompleted
an attached event $this
won't work and you need to use $source instead.
Upvotes: 9