Note that there are some explanatory texts on larger screens.

plurals
  1. POWinform->WPF MVVM Keybinding Error?
    text
    copied!<p>I need some assistance in getting WPF KeyBindings working when being called from a WinForm application. I've created what I think is the basic parts to demonstrate the problem. I can provide an sample application if that helps.</p> <p>The WinForm application starts a form which has a button that calls the WPF </p> <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim view As New WpfPart.MainWindow System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(view) view.ShowDialog() End Sub </code></pre> <p>With WPF view creates it's view model and sets up the keybings:</p> <pre><code>&lt;Window x:Class="WpfPart.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:WpfPart.ViewModels" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.DataContext&gt; &lt;vm:MainWindowViewModel /&gt; &lt;/Window.DataContext&gt; &lt;Window.InputBindings&gt; &lt;KeyBinding Key="Escape" Command="{Binding OpenCommand}" Modifiers="Control" /&gt; &lt;/Window.InputBindings&gt; &lt;Grid&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>The ViewModel uses a DelagateCommand to hopefully link everything up</p> <pre><code>using System; using System.Windows; using System.Windows.Input; using WpfPart.Commands; namespace WpfPart.ViewModels { class MainWindowViewModel { private readonly ICommand openCommand; public MainWindowViewModel() { openCommand = new DelegateCommand(Open, CanOpenCommand); } public ICommand OpenCommand { get { return openCommand; } } private bool CanOpenCommand(object state) { return true; } private void Open(object state) { MessageBox.Show("OpenCommand executed."); } } } </code></pre> <p>Can anyone see where it is going wrong, the keypress does nothing?!?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload