2012-03-01 5 views
0

silverlight 양식에서 tab 키로 입력 키를 변경하려면 어떻게해야합니까? 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

좋아. 고마워요. 완벽하게 작동합니다! 하지만 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; 
    } 

}