WPF - InputBindings binding View to ViewModel
"Gray, Franklin" <[email protected]> Tue, 28 Apr 2009 10:09:49 -0700
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <A0B440E225842C408347735A57AB04A3BEEE8E22@wwlkfmail1.wonderware.com> |
Hello all.
Short version: How do I bind the InputBindings on a WPF Usercontrol to a property on the object assigned to DataContent?
Long version: We use MVVM design but our first attempt at it so I can't say we have the pattern down pat. We have a Provider that supplies commands to the ViewModel and the View Binds the context menu to those commands. Works great, but now I need hot keys. Because only the Provider knows what the commands are and what keys should be assigned to them, it needs to provide a collection of these KeyBindings. That's easy. What I can't figure out, is how populate the View's InputBindings collection with the items in that property. I tried the following:
<!--<UserControl.InputBindings Source="{Binding Path=KeyBindings}" />-->
<!--<UserControl.InputBindings ItemsSource="{Binding Path=KeyBindings}" />-->
<!--<InputBindingCollection Source="{Binding Path=KeyBindings}" />-->
<!--<InputBindingCollection ItemsSource="{Binding KeyBindings}" />-->
None of these compile.
Property on DataContent (ViewModel) class:
System.Windows.Input.InputBindingCollection keyBindings = new System.Windows.Input.InputBindingCollection();
public System.Windows.Input.InputBindingCollection KeyBindings
{
get { return keyBindings; }
}
Franklin Gray
Senior Software Developer
Wonderware
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives