2017-01-01 25 views
0

後に私はこのようなメニューがあります。カーソルがValorInsTextBox(武勇テキストボックス)にあると私はEnterキーを押した場合、アプリはボタンを呼ぶことUWP XAMLテキストボックスのフォーカス入力し

enter image description here

I'dなどをInserirBtn_ClickAsync(Inserir Button)をクリックし、プロセスの後にカーソルをPosicaoInsTextBox(PosiçãoTextbox)に戻します。 Key_Downを使用していくつかのメソッドを作成しましたが、何か変わったことが起こります。コードを見て:私はコードをデバッグするときValorInsTextBoxが焦点であり、そしてこの方法ValorInsTextBox_KeyDownが起動し、すべてがうまく行くとき

private void PosicaoInsTxtBox_KeyDown(Object sender, KeyRoutedEventArgs e) 
{ 
    if (e.Key == Windows.System.VirtualKey.Enter) 
    { 
     InserirBtn_ClickAsync(sender, e); 

     PosicaoInsTxtBox.Focus(FocusState.Programmatic); 
    } 
} 

private void ValorInsTxtBox_KeyDown(Object sender, KeyRoutedEventArgs e) 
{ 
    if (e.Key == Windows.System.VirtualKey.Enter) 
    { 
     InserirBtn_ClickAsync(sender, e); 

     if (PosicaoInsTxtBox.IsEnabled) 
     { 
      PosicaoInsTxtBox.Focus(FocusState.Programmatic); 
     } 
     else 
     { 
      ValorInsTxtBox.Focus(FocusState.Programmatic); 
     } 
    } 
} 

、私はEnterキーを押します。そして、それがオンラインに到着したとき:

PosicaoInsTxtBox.Focus(FocusState.Programmatic); 

これは、PosicaoTextBox_KeyDownメソッドを実行して実行を開始します。どうしてか分かりません!誰でも私を助けることができますか?

答えて

1

あなたが呼び出されてからPosicaoInsTxtBox_KeyDownイベントハンドラを防ぐためにValorInsTxtBox_KeyDownイベントハンドラでtrueにKeyRoutedEventArgsのHandledプロパティを設定できます

private void ValorInsTxtBox_KeyDown(Object sender, KeyRoutedEventArgs e) 
{ 
    if (e.Key == Windows.System.VirtualKey.Enter) 
    { 
     InserirBtn_ClickAsync(sender, e); 

     if (PosicaoInsTxtBox.IsEnabled) 
     { 
      PosicaoInsTxtBox.Focus(FocusState.Programmatic); 
     } 
     else 
     { 
      ValorInsTxtBox.Focus(FocusState.Programmatic); 
     } 
    } 
    e.Handled = true; 
} 

から、それを防ぐためにPosicaoInsTxtBox_KeyDownイベントハンドラで同じことを行いますPosicaでEnterキーを押すと再び呼び出される "TextBox:

private void PosicaoInsTxtBox_KeyDown(Object sender, KeyRoutedEventArgs e) 
{ 
    if (e.Key == Windows.System.VirtualKey.Enter) 
    { 
     InserirBtn_ClickAsync(sender, e); 

     PosicaoInsTxtBox.Focus(FocusState.Programmatic); 
    } 
    e.Handled = true; 
} 
+0

これで問題は解決しました。ありがとうございました! –

関連する問題