Search code examples
wpfcommandbinding

How to do InputBindings for a DataBound ListBox?


I have a ListBox with ItemsSource bound. If anyone selects a ListBoxItem and presses Enter key, a command should be executed. How could I do this? I have ItemContainerStyle for ListBox and I cannot find a way to set InputBindings through Style.

Any ideas?


Solution

  • You could create an attached helper property which sets the bindings, here would be an example, you then can set that property in the style.