【发布时间】:2015-02-28 00:40:48
【问题描述】:
我有一个带有一些 KeyBindings 的 ListView,可以让用户使用键盘快捷键移动和删除条目。但是,我不希望始终可以访问绑定。
用于添加、删除和移动条目的按钮控件的可见性与 ComboBox 的选择相关(只有某些用户可以编辑)。我还希望根据框选择停用键盘快捷键。
我还没有找到任何关于这是否可行的信息。大家觉得呢?
<ComboBox x:Name="TesterIdentityBox" ItemsSource="{Binding Path=TesterIdentityList, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Name" SelectedItem="{Binding Path=TesterIdentitySelection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding TesterIdentityIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ListView ItemsSource="{Binding TestViewList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding SelectedTestIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Path=SelectedTest}">
<ListView.InputBindings>
<KeyBinding Key="Up" Command="{Binding Path=MoveTestUpCommand}" CommandParameter="{Binding Path=SelectedTest.Description}" />
<KeyBinding Key="Down" Command="{Binding Path=MoveTestDownCommand}" CommandParameter="{Binding Path=SelectedTest.Description}" />
<KeyBinding Key="Delete" Command="{Binding Path=RemoveTestCommand}" />
</ListView.InputBindings>
我使用带有 DataTriggers 的 Style Setter 来改变命令按钮的可见性,但我不知道什么(如果有的话)是 KeyBinding 等非可视元素的等价物。
【问题讨论】:
标签: wpf data-binding key-bindings