【发布时间】:2017-11-17 22:59:21
【问题描述】:
我有一个包含TextBox、ComboBox 和CheckBox 的表单,它们是从一个函数中填充的(例如textbox.text = "newValue";)。
private void updateIdentite(Contact c, Dal dal)
{
Identite id = dal.GetIdentite(c);
if (id != null)
{
idCivilite.SelectedValue = id.type_civilite;//example of a ComboBox
...
idNom.Text = id.pers_nom;//example of a TextBox
...
idAi.IsChecked = (id.cont_drap_ai == "1");//example of a CheckBox
...
}
}
当用户手动编辑项目时,我需要捕获一个事件,但使用TextChanged、SelectionChanged 或Checked,当表单被之前的函数填充时,这些事件也会被触发。
foreach (object item in identiteGrid.Children)
{
TextBox tb = item as TextBox;
if (tb != null)
{
tb.TextChanged += new TextChangedEventHandler(idTextBox_TextChanged);
continue;
}
ComboBox droplist = item as ComboBox;
if (droplist != null)
{
droplist.SelectionChanged += new SelectionChangedEventHandler(idCombobox_SelectionChanged);
continue;
}
CheckBox cb = item as CheckBox;
if (cb != null)
{
cb.Checked += new RoutedEventHandler(idCheckbox_Checked);
continue;
}
}
有没有办法为这些控件捕获“onInput”事件?
谢谢
【问题讨论】:
-
“当表单被上一个函数填充时”是什么意思?您指的是哪个“先前的功能”?
-
@mm8 "由函数填充(例如,使用 `textbox.text = "newValue";)"
-
@mm8 确实没必要,但已编辑。