Solved

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

Posted on 2014-02-06
4
799 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
Comment Utility
Have you implemented Interface, "INotifyPropertyChanged" in your viewmodel ?
0
 

Accepted Solution

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

Expert Comment

by:apeter
Comment Utility
Glad you solved with another "notification" interface.
0
 

Author Closing Comment

by:Navigator101
Comment Utility
The issue was sorted by someone direct emailing me..
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now