我有一些TextBoxes绑定到单个CheckBox.
这是与之相关的逻辑:
- 如果
Checkbox选中,它将覆盖关联中的任何现有文本TextBoxes并将其设为“0” ++ - 如果所有的
TextBoxes得分都是“0”,则CheckBox应该禁用并检查。 - 如果其中任何一个
TextBoxes从“0”更改,它将变为启用且未选中。
++ *注意: * 需要注意的是,如果 的TextBox值为“C”。
TextBoxes好的,所以我遇到的问题是当关联项之一的值为“C”时实施上述警告。我希望发生的是循环TextBoxes并检查是否有任何得分为“C”。如果找到,则向用户显示警告消息,确认他们是否要继续。如果选择“是”,所有相关分数将被覆盖为“0”。如果选择否,Checked则应取消该事件。
为此,我为CheckBox.PreviewMouseDown和CheckBox.Checked事件添加了事件侦听器。这是我的CheckBox.PreviewMouseDown事件监听器的代码:
private void NormalCheckBoxControl_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
CheckBox normalCheckBox = (CheckBox)sender;
bool showCorrespondingScoreWarningMsg = false;
//Get a Row to loop through the AssociatedAdqScore controls for each
ScoreControl tempScoreControl = new ScoreControl();
foreach (ScoreControl score in this.ScoreControlList)
{
if (score.ScoreTextBox.Text == "C")
{
showCorrespondingScoreWarningMsg = true;
}
}
if (showCorrespondingScoreWarningMsg)
{
MessageBoxResult msgResult = InformationBox.Show("WARNING: Proceeding will remove corresponding 'C' scores. Continue?", "Continue?", ButtonStyle.YesNo, IconStyle.Question);
if (msgResult == MessageBoxResult.No)
{
e.Handled = true;
}
}
}
This works if the user selects 'No,' however the issue I'm having is that when choosing 'Yes,' the CheckBox.Checkedevent still does not get fired. 我试图手动设置CheckBox.IsChecked = true;if if (msgResult == MessageBoxResult.Yes),但这会破坏绑定,因此这不是一个可行的解决方案。
如果用户选择“是” ,我有什么办法可以解决此问题并继续该NormalCheckBoxControl_Checked(object sender, RoutedEventArgs e)事件?