Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 102901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:02:20+00:00 2026-05-11T01:02:20+00:00

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

  • 0

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 and showing others.

If a validation exception is set – i.e. the UI is showing a red border around the UI element with the validation problem, and the containing panel is collapsed, the red border is still displayed. This is clearly not meant to be? Is there a workaround for this? Anyone know if this is by design?

Minimal code example provided (not my actual code, but replicates the problem). Create a new WpfApplication (I called mine WpfDataBindingProblem).

The xaml for window1 is as follows:

<Window x:Class='WpfDataBindingProblem.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'>     <StackPanel Margin='5'>          <StackPanel Name='panel1' Visibility='Visible' Margin='5'>             <TextBox Name='DataBoundTextBox'>                 <Binding Path='TextValue'>                     <Binding.ValidationRules>                         <ExceptionValidationRule/>                     </Binding.ValidationRules>                 </Binding>             </TextBox>         </StackPanel>          <StackPanel Name='panel2' Visibility='Collapsed' Margin='5'>             <TextBlock>                 The quick brown fox jumps over the lazy dog.             </TextBlock>         </StackPanel>          <Button Click='Button_Click' Margin='5'>             Toggle panels         </Button>      </StackPanel> </Window> 

The code for window1 is as follows:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;  namespace WpfDataBindingProblem {      public partial class Window1 : Window {         public Window1() {             InitializeComponent();              this.DataContext = new MyClass('default');         }          private void Button_Click(object sender, RoutedEventArgs e) {             panel1.Visibility = panel1.Visibility == Visibility.Collapsed ?                 Visibility.Visible : Visibility.Collapsed;             panel2.Visibility = panel2.Visibility == Visibility.Collapsed ?                 Visibility.Visible : Visibility.Collapsed;         }     }      public class MyClass : INotifyPropertyChanged {          private string mTextValue;          public MyClass(string defaultText) {             TextValue = defaultText;         }          public string TextValue {             get {                 return mTextValue;             }             set {                 mTextValue = value;                 if (string.IsNullOrEmpty(mTextValue)) {                     throw new ApplicationException('Text value cannot be empty');                 }                 OnPropertyChanged(new PropertyChangedEventArgs('TextValue'));             }         }          public event PropertyChangedEventHandler PropertyChanged;          protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {             if (this.PropertyChanged != null) {                 this.PropertyChanged(this, e);             }         }     }  } 

To reproduce the problem, run the application. Delete the default text from the textbox and tab off – red rectangle is shown indicating a validation problem. Click the button. Panel containing control with red rectangle is hidden and another panel is shown, but the red rectangle remains. Aargh!

All help much appreciated.

PS apologies for long question title!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:02:20+00:00Added an answer on May 11, 2026 at 1:02 am

    If I remember correctly, this is a known issue. We re-templated textbox to include the following:

    <Setter Property='Validation.ErrorTemplate'>     <Setter.Value>         <ControlTemplate>             <ControlTemplate.Resources>                 <BooleanToVisibilityConverter x:Key='converter' />         </ControlTemplate.Resources>             <DockPanel LastChildFill='True'>                 <Border                      BorderThickness='1'                     BorderBrush='Red'                     Visibility='{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource converter}}'>                     <AdornedElementPlaceholder x:Name='placeholder' />                 </Border>              </DockPanel>          </ControlTemplate>     </Setter.Value> </Setter> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 160k
  • Answers 160k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, where to start? Here is just a first observation:… May 12, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer There's a page in in the C# FAQ about this… May 12, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer You can push the current request into the Session, then… May 12, 2026 at 11:39 am

Related Questions

I have a situation where I want to convert a RTF document to image
I have a situation where i need to enforce a unique constraint on a
I have a LINQ query: var result = from mt in MessageTypes join mtfmt
I have a class called Player in the business layer of my web application.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.