一、cs
#region
private List<TextBox> _filterByTextBoxList = null;
private List<RadComboBox> _filterByComboBoxList = null;
private void TextBox_FilterBy_Loaded(object sender, RoutedEventArgs e)
{
TextBox c = sender as TextBox;
if (_filterByTextBoxList == null)
{
_filterByTextBoxList = new List<TextBox>();
}
_filterByTextBoxList.Add(c);
}
private void TextChangedHandler(object sender, RoutedEventArgs e)
{
TextBox txtbox = ((Control)sender) as TextBox;
//if (txtbox.Text.Length == 4 && (txtbox.Name == "depap" || txtbox.Name == "arrap"))
//{
// ReBinding(sender);
//}
Action<object, RoutedEventArgs> tt = new Action<object, RoutedEventArgs>(ChangeFocus);
this.Dispatcher.BeginInvoke(tt, System.Windows.Threading.DispatcherPriority.Normal, sender, e);
e.Handled = true;
}
private void ComboBox_FilterBy_Loaded(object sender, RoutedEventArgs e)
{
RadComboBox c = sender as RadComboBox;
if (_filterByComboBoxList == null)
{
_filterByComboBoxList = new List<RadComboBox>();
}
_filterByComboBoxList.Add(c);
}
private void ChangeFocus(object sender, RoutedEventArgs e)
{
string name = ((Control)sender).Name;
TextBox txtbox = ((Control)sender) as TextBox;
//RadComboBox comboBox = ((Control)sender) as RadComboBox;
if (((Control)sender).DataContext != null)
{
FsViewDataBase fvbase = viewModel.CurrentFvd;
if (name == "tbbegin" && txtbox.Text.Length == 5)
{
TextBoxFocus("tbend", fvbase.SEQ);
}
else if (name == "tbend" && txtbox.Text.Length == 5)
{
TextBoxFocus("depap", fvbase.SEQ);
}
else if (name == "depap" && txtbox.Text.Length == 4)
{
TextBoxFocus("txtDeptime", fvbase.SEQ);
}
else if (name == "txtDeptime" && txtbox.Text.Length == 4)
{
TextBoxFocus("txtArrtime", fvbase.SEQ);
}
else if (name == "txtArrtime" && txtbox.Text.Length == 4)
{
TextBoxFocus("arrap", fvbase.SEQ);
}
else if (name == "arrap" && txtbox.Text.Length == 4)
{
ComboBoxFocus("cboRoute", fvbase.SEQ);
}
}
}
private void TextBoxFocus(string txtName, int seq)
{
try
{
for (int i = 0; i < _filterByTextBoxList.Count; i++)
{
TextBox c = _filterByTextBoxList[i];
int tag = Convert.ToInt32(c.Tag);
if (c != null)
{
if (c.Name == txtName && tag == seq)
{
c.Focus();
c.Select(0, c.Text.Length);
}
}
}
}
catch (Exception)
{
}
}
private void ComboBoxFocus(string comName, int seq)
{
try
{
for (int i = 0; i < _filterByComboBoxList.Count; i++)
{
RadComboBox c = _filterByComboBoxList[i];
int tag = Convert.ToInt32(c.Tag);
if (c != null)
{
if (c.Name == comName && tag == seq)
{
c.Focus();
c.IsHighlighted = true;
}
}
}
}
catch (Exception)
{
}
}
#endregion
二、界面
指定Name=“”、TextChanged="TextChangedHandler" 、Loaded="TextBox_FilterBy_Loaded"