0
我想設置的ListViewItem的Inputbinding ......這應該是一個Keyborad約束力,而不是鼠標結合...設置InputBinding(KeyboardBinding)在ListViewItem的
我想在我的視圖模型來執行一個功能當用戶selectes一個項目,並按下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>
我的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中,以及在樣式沒有
<KeyBinding Key="Enter" Command="{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" CommandParameter="{Binding}"></KeyBinding>
我使用.NET 4.0客戶端配置文件。 ...我甚至試圖使用Net 4.0的KeyBinding.Command作品,如果我在選擇ListViewitem後按下「Tab」。 – Ankesh
我想,我必須將輸入綁定在ListView ... – Ankesh
但什麼情況下,我必須爲ListView和ListViewItem設置輸入綁定使用相同的鍵來爲ListView執行不同的功能& ListViewItem' .... – Ankesh