English 中文(简体)
我如何能够在进入关键媒体上启动一个纽芬兰的浮雕指挥?
原标题:How can I activate a button s Click command on Enter key press?

I m 采用SL Prism和MEF,使用MVVER。

我的日志网页目前载有一个用户名和密码文本箱和一个单一日子。 我的纽特法典如下:

<Button x:Name="signInButton" Content="Sign In" cal:Click.Command="{Binding loginCommand}"/>

What I m struggling with is wiring up the textbox so that if the user hits enter the loginCommand executes. I ve done a lot of googling and can t seem to find any answers that cope with MVVM.

我试图在控制线上增加一个主要活动手。 然而,从我所能实现的唯一东西背后的法典来看,它把重点放在纽伦。

private void StackPanel_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        this.signInButton.Focus();
        e.Handled = true;
    } 
}

我怎么能够达到要求执行标志的进入钥匙的目标?

Many Thanks James

最佳回答

Use the Automation Peer classes to press it. This will then work with an MVVM ICommand like the one you have:

ButtonAutomationPeer peer =
  new ButtonAutomationPeer( someButton );

IInvokeProvider invokeProv =
  peer.GetPattern( PatternInterface.Invoke )
  as IInvokeProvider;

invokeProv.Invoke();
问题回答

在<代码>KeyDown上添加“参数(费用)”的活动——应当援引指挥系统。 如果钥匙是Key.Enter 那么,只是援引指挥。

Can you just call the click method? For instance inside of your capture of the Enter button where "this.signInButton.Focus();" is, put "signInButton_Click(null, null);" to fire the button s click method directly.

您可以增加Xaml具体指挥的钥匙,例如:

 <Button Command="{Binding TestCommand}" Content="Test">
        <Button.InputBindings>
            <KeyBinding Command="{Binding TestCommand}" Key="F2" />
        </Button.InputBindings>
    </Button>

那么,如果你的布特顿重点突出,关键议题就能够发挥作用。 如果你想在更大范围内提供贵重物品,你可以把钥匙包添加到窗口(窗户)。 关键事项或任何其他要素。





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签