Solved

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

Posted on 2014-02-06
4
807 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now