Reputation: 51
I have a MouseDoubleClick event in the following .xaml file which is not firing properly:
<Style TargetType="controls:Source" x:Key="{x:Type controls:Source}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Source">
<Border BorderThickness="0.8" CornerRadius="10" BorderBrush="{TemplateBinding Foreground}"
d:DataContext="{d:DesignInstance d:Type=viewModels:SourceViewModel}">
<Grid Style="{StaticResource ElementThatClipsToParentBordersStyle}">
<Image Source="{Binding AttachedSource.Image, RelativeSource={RelativeSource TemplatedParent}}" Stretch="Fill" />
<Border x:Name="Selection"
Opacity="0.3"
Background="{TemplateBinding Foreground}"
Visibility="Collapsed"
IsHitTestVisible="False"/>
</Grid>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<interactivity:InvokeCommandAction Command="{Binding DataContext.SelectionState.ClickSourceCommand, ElementName=SourcesControl}"
CommandParameter="{Binding}" />
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<interactivity:InvokeCommandAction Command="{Binding PreviewLeftClickCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseMove">
<interactivity:InvokeCommandAction Command="{Binding MouseMoveCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseDoubleClick">
<interactivity:InvokeCommandAction Command="{Binding SourceDoubleClickCommand}"
CommandParameter="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Selection" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Every others event works just fine and as intended but the command bound to the MouseDoubleClick event is not executed.
The weird thing is that when I use another event such as MouseLeftButtonDown everything is working, so the problem does not seem to be connected to the excuted command but to the used event itself.
Of course I could work around this problem by using a simple MouseLeftButtonDown event and check for the time of the last click to identify a doubleclick but the built-in doubleclick event seems to be better way to go for me.
Does someone have an idea why the MouseDoubleClick event is not firing properly in this scenario?
Upvotes: 3
Views: 8219
Reputation: 459
Border
does not have a MouseDoubleClick
event, because it is not a control.
There are a couple of ways of making a MouseDoubleClick
available. See Why doesn't WPF border control have a mousedoubleclick event?.
A straightforward way is to wrap your border in a ContentControl
which raises the MouseDoubleClick
event (from http://blogs.microsoft.co.il/pavely/2011/08/03/wpf-tip-using-a-mousedoubleclick-event-where-none-exists/):
<ContentControl MouseDoubleClick="OnDoubleClick">
<Border Margin="10" BorderBrush="Black" BorderThickness="2">
<Grid Margin="4">
<Rectangle Fill="Red" />
<TextBlock Text="Hello" FontSize="15" />
</Grid>
</Border>
</ContentControl>
Upvotes: 5