Solved

How do you get WPF ViewModel to notify a UI control from code behind?

Posted on 2014-02-06
4
815 Views
Last Modified: 2014-02-17
In a WPF forms app, I have MVVM Validation (using the MVVMValidationHelper, which is excellent) working against a number of fields so that any user interaction with a control triggers validation and applies a simple Validation.ErrorTemplate when the value found to be invalid.
The problems is; changes to the bound VM properties from code behind do not notify the UI that a property is now in an invalid state to apply the ErrorTemplate - The validation is only getting applied to the control when the user is interacting with a particular time.

e.g. User changes value A, which validates and cause the B to become invalid via its rules.  The control bound to B need to now be adorned with the ErrorTempalte.

Is there a way to notify controls bound to properties that have had their validation state changed?


XAML
<TextBox Text="{Binding Xxxxxxx, Mode=TwoWay, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ValidationTemplate}" />

Open in new window

VM
private string _Xxxxxxx= string.Empty;
public string Xxxxxxx
{
   get { return _Xxxxxxx; }
   set
      {
         if (Set<string>(() => Xxxxxxx, ref _Xxxxxxx, value))
              Validator.Validate(() => Xxxxxxx);
      }
}

Open in new window

0
Comment
Question by:Navigator101
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:apeter
ID: 39841412
Have you implemented Interface, "INotifyPropertyChanged" in your viewmodel ?
0
 

Accepted Solution

by:
Navigator101 earned 0 total points
ID: 39853433
Yes - the issue was around the implementation of the IDataErrorInfo notification - once this was implemented it worked
0
 
LVL 25

Expert Comment

by:apeter
ID: 39853580
Glad you solved with another "notification" interface.
0
 

Author Closing Comment

by:Navigator101
ID: 39864300
The issue was sorted by someone direct emailing me..
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question