Im在TextBox中存在Selecting All
內容的問題。TextBox的所有內容的選擇在WPF中未按預期方式工作
Ussually按enter我從一個文本框跳到另一個,因爲有喜歡對方 低於6-7文本框在我的網格,並通過按下輸入我需要從一個到另一個跳,
private void Grid_PreviewKeyDown_1(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
UIElement element = e.Source as UIElement;
element.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
//TextBox tb = (sender as TextBox);
//if (tb != null)
//{
// tb.SelectAll();
//}
}
}
雖然我對他們中的一些,當我按下Enter鍵,我做了一些計算是這樣的:
private void txt2_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
try
{
CalculateSomethingFromOtherTextBoxes();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
我的問題是下一:當我從對方跳,當我完成計算(輸入被按下),我將跳到下一個文本框當我跳上它的時候會喜歡TextBox內容的SELECTALL。 如果我想編輯一些值或任何其他內容,並且有時令內容混淆,有時內容被選中,有時不是。
我想每個文本框的設置GotFocus事件和它看起來像這樣:
private void txt3_GotFocus(object sender, RoutedEventArgs e)
{
txt3.SelectAll();
}
不過可惜的是不知何故這有時有時工作不是,我的意思是所有的內容有時選擇有時是不..
謝謝你們 乾杯
如何在此解決方案的行爲? http://stackoverflow.com/a/1264633/503059 – Staeff