How do I get rid of the red rectangle when my wpf binding validation has failed and the containing panel is no longer visible?

前端 未结 2 725
情深已故
情深已故 2020-12-08 15:20

I have a situation where I am using wpf data binding and validation using the ExceptionValidationRule.

Another part of the solution invovles collapsing some panels a

2条回答
  •  眼角桃花
    2020-12-08 16:19

    I have an answer to the problem myself which is to change my button click event which changes the visibility of the panels. This would change to something like this:

    private void Button_Click(object sender, RoutedEventArgs e) {
        if (panel1.Visibility == Visibility.Collapsed) {
            panel1.Visibility = Visibility.Visible;
            DataBoundTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            panel2.Visibility = Visibility.Collapsed;
        }
        else {
            panel1.Visibility = Visibility.Collapsed;
            DataBoundTextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
            panel2.Visibility = Visibility.Visible;
        }
    }
    

    The UpdateSource() and UpdateTarget() have the effect of reapplying and removing the red rectangle, but this seems like an ugly hack. Surely the wpf framework should be hiding the red rectangle for me when the containing panel is collapsed. Any cleaner fix that doesn't require me to fiddle with the binding expression gets my vote.

    Thanks,

    Sam

提交回复
热议问题