English 中文(简体)
Winform->WPF MVVER Key binding Error?
原标题:Winform->WPF MVVM Keybinding Error?

我需要获得一些援助,帮助在接到“温恩”申请时,让世界森林基金会的关键问题发挥作用。 我认为,我是表明这一问题的基本要素。 如果能够这样做,我可以提供样本。

WinForm的申请开始采用一种叫做WPF的纽芬兰语。

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

计生联认为它树立了看法模式,并建立了关键词:

<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">
<Window.DataContext>
    <vm:MainWindowViewModel />
</Window.DataContext>
<Window.InputBindings>
    <KeyBinding Key="Escape" Command="{Binding OpenCommand}" Modifiers="Control" />
</Window.InputBindings>
<Grid>

</Grid>

The ViewModel use a DelagateCommand to Hopelylink all up

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.");
    }
}
}

谁会看它会错在哪里,关键压力是什么?

最佳回答

为了使重要工作成为你需要把指挥对你的窗口给予更多的关注。 经费,然后由总统办公厅(而不是指挥部)参考。

我也利用控制-X避免在视窗上打开“起始纽”图以控制-E替因。

你可以在此根据你的问题使用XAML:

<Window.Resources>
    <!-- Allows a KeyBinding to be associated with a command defined in the View Model  -->
    <c:CommandReference x:Key="OpenCommandReference" Command="{Binding OpenCommand}" />
</Window.Resources>
<Window.InputBindings>
    <KeyBinding Key="X" Command="{StaticResource OpenCommandReference}" Modifiers="Control" />
</Window.InputBindings>
问题回答

In mi project i used solution: suppose, ListView Has items of DummyViewModel with command CmdDelete, and i need to invoke this command under selected item preesing Delete key

<Grid>
    <Button x:Name="DeleteCmdReference" Visibility="Collapsed" Command="{Binding Source={x:Reference MyListView},Path=SelectedItem.CmdDelete}" />
    <ListView x:Name="MyListView" ...="" >
      <ListView.InputBindings>
        <KeyBinding Key="Delete" Command="{Binding ElementName=DeleteCmdReference,Path=Command}"/>
      </ListView.InputBindings>
    </ListView>
  </Grid>




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签