2016-12-20 60 views
-1

我有8個最大長度爲1的小文本框,我想這樣做當有人在其中一個框中鍵入一個字符時,它會自動將光標移動到沒有用戶不得不按下Tab或手動點擊贏在下一個盒子10 UWp 有沒有簡單的方法來做到這一點?在UWP中自動移動光標到下一個文本框

+0

請參考:stackoverflow.com/help/how-to -問。並努力完成2分鐘的現場參觀。 –

回答

0

它自動將光標移動到下一個盒子,用戶不必按Tab或手動點擊下一個盒子在勝利10 UWp有沒有一種簡單的方法來做到這一點?

Focus方法將是你想要的。如果您通過鍵盤交互設置焦點(如選項卡序列或按鍵),請將FocusState.Keyboard作爲參數。

我做了一個簡單的代碼示例,供您參考:

<StackPanel Orientation="Horizontal" Height="50"> 
     <TextBox x:Name="txb1" MaxLength="1" Width="20" TextChanged="txb_TextChanged"></TextBox> 
     <TextBox x:Name="txb2" MaxLength="1" Width="20" TextChanged="txb_TextChanged" Margin="10 0 0 0"></TextBox> 
</StackPanel> 

private void txb_TextChanged(object sender, TextChangedEventArgs e) 
{ 
    TextBox textbox = sender as TextBox; 
    if (!string.IsNullOrEmpty(textbox.Text.Trim())) 
    { 
     txb2.Focus(FocusState.Keyboard); 
    } 
} 

enter image description here

相關問題