开发者

How to add Add key binding to DataGrid column level?

I have a WPF DataGrid with few co开发者_JAVA技巧lumns. Now i try to add the short cut key "Shift+$" into one of the DataGrid column. What I want to achieve is that when user on the partipular column, then press "Shift + $", it fire command. If user on other columns, "Shift + $" works as normal input.

Can anyone give me some idea how I can achieve this?

Thanks

Jing


The options are a bit limited with datagrid columns, i tried doing it this way:

<DataGridTextColumn Binding="{Binding Name}">
    <DataGridTextColumn.EditingElementStyle>
        <Style>
            <EventSetter Event="FrameworkElement.Loaded" Handler="DG_NameColumn_Loaded"/>
        </Style>
    </DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
private void DG_NameColumn_Loaded(object sender, RoutedEventArgs e)
{
    var tb = sender as TextBox;
    tb.InputBindings.Add(new KeyBinding(Commands.DoStuff, new KeyGesture(Key.D4, ModifierKeys.Shift)));
}

Unfortunately this throws an exception telling you that Shift+D4 is not supported by KeyGesture. I think your plan might not work out anyway...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜