イベントでtextbox1
データをバインドしています。LostFocus
キーボードナビゲーションを設定しました。Tabindex=7
fortextbox1
および for textbox2
keyboardNavigation TabIndex=8
。今私の問題は、 の正規表現検証を行ってtextbox1
いることtextbox1
です. どうすればこれを達成できますか?MessageBox
textbox2
textbox1
私はこの方法を試しました:
if (!string.IsNullOrEmpty(txtbox1.Text))
{
if(Regex.IsMatch(txtbox1.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
txtbox2.Text = "(" + txtbox1.Text + ")";
}
else
{
MessageBoxResult mbr;
mbr=MessageBox.Show("please enter valid Email Id", "VMS", MessageBoxButton.OK, MessageBoxImage.Error);
if (mbr == MessageBoxResult.OK)
{
Keyboard.Focus(txtbox1);
txtbox1.Clear();
// txtbox1.TabIndex = 7;
//txtbox1.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
// txtbox2.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
//txtbox1.Focus();
// KeyboardNavigation.SetTabIndex(txtbox1, 6);
}
}
else
{
txtbox2.Text = string.Empty;
// txtbox1.TabIndex = 7;
//txtbox1.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
//KeyboardNavigation.SetTabIndex(txtbox1, 7);
// txtbox2.TabIndex=7;
//Keyboard.Focus(txtbox2);
}
txtbox1
テキスト入力が無効な場合にキーボード ナビゲーションを設定するにはどうすればよいですか? なにか提案を。
編集:xamlを追加
<Window x:Class="DataBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBox Name="txtbox1" Margin="71,22,82,195" LostFocus="txtbox1_LostFocus" />
<TextBox Name="txtbox2" Margin="71,96,82,127" />
</Grid>