Solved

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

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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