开发者

InvokeCommandAction won't work when used in an EventTrigger?

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜