?
Solved

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

Posted on 2014-02-06
4
Medium Priority
?
851 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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