这是我关于堆栈溢出的第一个问题所以请保持温和: - )
在我的一个WPF窗口中,我有一个列表框,其项目使用以下数据模板进行模板化:
<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>
注意网格中的两个触发器:
在我的视图模型上调用ICommand的KeyTrigger
一个EventTrigger应该完全相同但由于某些未知原因不会
任何人都可以向我解释原因吗? 感谢您的时间和考虑
斯文
答案 0 :(得分:3)
事情是没有MouseDoubleClick
事件...
但我相信使用ImputBindings
:
<Grid Background="#77ffffff" Margin="0">
<Grid.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding SelectModelCommand}"/>
</Grid.InputBindings>
...
</Grid>