2012-03-01 14 views
0

SilverlightフォームのEnterキーをtab key.iに変更するにはどうすればよいですか?winformsで次のコードを使用します。SilverlightフォームのTabキーにEnterキーを変更します。

/// <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); 
} 
+0

私はちょうどあなたが期待される結果は、コードが働いていた場合はお知らせ気軽に返す必要がありますどのようにお見せしたかった...以下の例では、コードのすべてを入れていなかった...で動作しません – MethodMan

答えて

1

Silverlightでは、どのキーが押されたかを確認できるKeyDownイベントがあります。 KeyDownイベントに関数を書くことができます。e.key == Enterキーが目的のTextBoxにフォーカスを移動した場合にEnterを押します。

+0

感謝シルバーライト –

+1

とはどういう意味では動作しませんか?より具体的な..これは動作するはずですが、私は何かをチェックしてみましょう.. – MethodMan

+0

ok.t​​hank you.itの仕事は完璧です! SilverlightでSendKeysで実装することはできますか? –

2

少し遅れていますが、誰でもこのスレッドを表示しています - 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; 
    } 

} 
関連する問題