1

this is my first question on stack-overflow so please be gentle :-)

In one of my WPF windows I have a listbox whose items are templated with the following data template:

<ListBox.ItemTemplate>
<DataTemplate>
    <Grid UseLayoutRounding="True" Width="80">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Border
            Grid.Row="0"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
        >

            <Viewbox 
                Height="110"
                Width="50"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
            >
            <Grid Background="#77ffffff" Margin="0">
                <i:Interaction.Triggers>
                    <ei:KeyTrigger Key="Return">
                        <i:InvokeCommandAction 
                            Command="{Binding SelectModelCommand}"
                            CommandParameter="{Binding}"
                        />
                    </ei:KeyTrigger>
                    <i:EventTrigger EventName="MouseDoubleClick">
                        <i:InvokeCommandAction 
                            Command="{Binding SelectModelCommand}"
                            CommandParameter="{Binding}"
                        />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Path Stroke="{DynamicResource FontBrush}"
                    StrokeThickness="100"
                    Data="{Binding DrawingPathString, FallbackValue={x:Static bll:Panel.NoDrawing}}"/>
            </Grid>
            </Viewbox>
        </Border>

        <TextBlock 
            Grid.Row="1"
            FontSize="8"                
            TextWrapping="NoWrap"  
            HorizontalAlignment="Center"
            Text="{Binding Path=BLLPanel.Model,FallbackValue=MODEL}"
        />
        <TextBlock 
            Grid.Row="2"
            FontSize="8"                
            TextWrapping="NoWrap" 
            HorizontalAlignment="Center"
            Text="{Binding Path=BLLPanel.PanelFamily.Description,FallbackValue=FAMILY}"
        />
    </Grid>
</DataTemplate>

Notice the two triggers in the Grid:

  • a KeyTrigger that invokes an ICommand on my view model

  • an EventTrigger that should do exactly the same but for some unknown reason doesn't

Can anyone explain to me why ? Thanks for your time and consideration

Sven

desfen
  • 11
  • 1
  • 3
  • Is the command object you're binding to (SelectModelCommand) returning true for CanExecute? – Mark Staff May 23 '11 at 12:31
  • Hi, thanks for answering. To answer your question: yes, the ICommand is returning the correct value. This is evidenced by the fact that the KeyTrigger IS working as expected. – desfen May 23 '11 at 12:55

1 Answers1

3

The thing is that there is no MouseDoubleClick event...

But I believe what you are trying to do can be easily achieved using ImputBindings:

<Grid Background="#77ffffff" Margin="0">
            <Grid.InputBindings>
                <MouseBinding Gesture="LeftDoubleClick" Command="{Binding SelectModelCommand}"/>
            </Grid.InputBindings>
    ...
</Grid>
Pavlo Glazkov
  • 20,498
  • 3
  • 58
  • 71
  • Thanks for your answer Pavlo. I'll have to try it out to see if this works out (I'm otherwise engaged at this time). – desfen May 24 '11 at 07:53
  • Update: it turns it pavlo's suggestion didn't work out either. According to [this thread on the msdn forums](http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/da54880a-b11c-4d3b-995b-546055398997) this is due to a bug in WPF. :-( I ended up following Marco Zhou's suggestion of handling PreviewMouseDoubleClick in the code-behind. Yuck ! Shame on you Microsoft for not having fixed this bug yet. – desfen Jan 10 '12 at 10:41