Я хочу установить привязку ввода для listViewitem ... Это должна быть привязка Keyborad, а не привязка мыши ...
Я хочу выполнить функцию в моей модели представления, когда пользователь выбираетэлемент и нажатия Enter
Ключ
Стиль для ListViewItem
<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type CustomView:PlainView},
ResourceId=ImageViewItem}"
TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FocusVisualStyle" Value="{StaticResource ListViewItemFocusVisual}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="0,0,0,1" />
<Setter Property="Padding" Value="5,2,5,2" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Focusable" Value="False"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border x:Name="border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="2"
SnapsToDevicePixels="true">
<Grid Margin="2,0,2,0">
<Rectangle x:Name="BackgroundGradientOver"
Fill="{DynamicResource MouseOverBrush}"
Opacity="0"
RadiusX="1"
RadiusY="1"
Stroke="{DynamicResource MouseOverBorderBrush}" />
<Rectangle x:Name="BackgroundGradientSelectedDisabled"
Fill="{DynamicResource ListItemSelectedBrush}"
Opacity="0"
RadiusX="1"
RadiusY="1"
Stroke="{DynamicResource ListItemSelectedBorderBrush}" />
<Rectangle x:Name="BackgroundGradientSelected"
Fill="{DynamicResource PressedBrush}"
Opacity="0"
RadiusX="1"
RadiusY="1"
Stroke="{DynamicResource PressedBorderBrush}"
StrokeThickness="1" />
<ContentPresenter x:Name="contentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource OutsideFontColor}" />
</Style>
My DataTemplate
<DataTemplate x:Key="centralTile">
<StackPanel Width="80"
Height="40"
KeyboardNavigation.AcceptsReturn="True">
<StackPanel.InputBindings>
<KeyBinding Key="Enter" Command="{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" CommandParameter="{Binding}"></KeyBinding>
</StackPanel.InputBindings>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Command="{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}"
CommandParameter="{Binding}">
<TextBlock Text="{Binding Path=Name}" />
</Button>
<Image Grid.Column="1" Source="Water lilies.jpg" />
</Grid>
<TextBlock HorizontalAlignment="Center"
FontSize="13"
Text="{Binding Path=Name}" />
</StackPanel>
</DataTemplate>
Я не могу найти способ сделать это ...
Я прикрепил свою InputBinding в DataTemplate, а в Style ничего не работает
<KeyBinding Key="Enter" Command="{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" CommandParameter="{Binding}"></KeyBinding>