将输入键更改为银色窗体中的Tab键
本文关键字:窗体 Tab 输入 | 更新日期: 2023-09-27 18:26:25
如何将silverlight表单中的回车键更改为tab键。我在winforms中使用了以下代码,但我不知道如何在silverlight中实现这一点!
/// <summary>
/// Change Enter key To Tab Key
/// </summary>
/// <param name="msg"></param>
/// <param name="keyData"></param>
/// <returns></returns>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (msg.Msg == 256 && keyData == Keys.Enter)
{
// Execute an alternative action: here we tabulate in order to focus on the next control in the formular
if (ActiveControl.ToString().Contains("System.Windows.Forms.Button") ||
ActiveControl.ToString().Contains("DevComponents.DotNetBar.ButtonX"))
return base.ProcessCmdKey(ref msg, keyData);
SendKeys.Send("{TAB}");
// return true to stop any further interpretation of this key action
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
有点晚了,但任何人都可以查看此线程-在Silverlight 5中使用AutomationFactory按ENTER键时可以使用TAB键。我通过编写一个行为来做到这一点,在该行为中,您可以收听KeyDown并传入TAB键。应用程序必须在OOB模式下运行。您可以将此行为附加到Blend中的文本框中。
public class EnterKeyPropertyChangeBehaviour : Behavior<DependencyObject>
{
public EnterKeyPropertyChangeBehaviour()
{
}
protected override void OnAttached()
{
base.OnAttached();
// Insert code that you would want run when the Behavior is attached to an object.
var fe = AssociatedObject as FrameworkElement;
if (fe != null) fe.KeyDown += fe_KeyDown;
}
void fe_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
shell.SendKeys("{TAB}");
}
}
}
protected override void OnDetaching()
{
base.OnDetaching();
// Insert code that you would want run when the Behavior is removed from an object.
var fe = AssociatedObject as FrameworkElement;
if (fe != null) fe.KeyDown -= fe_KeyDown;
}
}
在Silverlight中,我们有KeyDown事件,可以检查按下了哪个键。您可以在KeyDown事件和该检查中编写一个函数。如果e.key==Enter键按下,则将焦点集中到您想要的Desired TextBox。