Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6351039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:55:32+00:00 2026-05-24T21:55:32+00:00

In Silverlight 3 I am working with a MVVM and also the validation principle

  • 0

In Silverlight 3 I am working with a MVVM and also the validation principle that the setters cause an exception if a validation error occurs. I using the Binding Syntax on the fields using TwoWay i.e.:

<TextBox x:Name="TextBoxClientName" Text="{Binding Name,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=true}"  Grid.Column="1" Grid.Row="0" Margin="5 5 5 5" />

I validate this property in the ViewModel using the Annotations:

[Required(ErrorMessage = "Name is required")]
public string Name
{
    get
    {
        return _client.Name;
    }
    set
    {
        Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "Name", DisplayName="Client Name" });
        _client.Name = value;
    }
}

I have the Validation summary and all work well BUT lol, the functionality I am looking for is the following:

You have the Data Form and I want the validation summary to appear over the top ONLY when I click save, and further more I want to implement a close button on that ValidationSummary so the user can continue on with entering and correcting.

I am not sure how to control the visibility or toggle of with the validationsummary, I have tried the Visibility. The following is code that I tried, WHICH does collect the errors on submit, but I cannot apply them to the validationsummary:

    public void Save()
    {
        List<ValidationError> errors = new List<ValidationError>();

        foreach (UIElement ui in LayoutRoot.Children)
        {
            FrameworkElement fe = ui as FrameworkElement;

            if (fe != null)
            {
                foreach (ValidationError ve in Validation.GetErrors(fe))
                {
                    errors.Add(ve);
                }
            }
        }


        if (errors.Count > 0)
        {

            Validation1.DataContext = errors;
            Validation1.Filter = ValidationSummaryFilters.All;
        }
        else
        {
            if (Saved != null)
                Saved(this, EventArgs.Empty);
        }

    }

Cheers,

Andrew

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:55:34+00:00Added an answer on May 24, 2026 at 9:55 pm

    I guess that by now you’re using SIlverlight 4 in your apps. So this answer is for Silverlight 4.

    With Silverlight 4 a new interface was added INotifyDataError with 3 methods:

    public interface INotifyDataErrorInfo 
    {
        // Returns True if the object has at least one property-level or top-level error. 
        bool HasErrors { get; }
    
        // Returns the current set of property-level errors for the provided property name, or
        // the current top-level errors if the argument is null or empty. 
        IEnumerable GetErrors(string propertyName);
    
        // Raised when the set of errors for a particular property has changed, or when the 
        // top-level errors have changed. 
        event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
    }
    

    There is vast documentation around the web about that interface and how to use it.

    You don’t have to use DataAnotations if you don’t want to. But if you do, you still will be able to get the validation errors using the Validator class from the System.ComponentModel.DataAnnotations namespace.

    If you make your ViewModel implement INotifyDataError and have also a property (in the ViewModel) bool IsValidating or something like that. Then every time the property changes fire the ErrorsChanged event for all the properties that you want to validate (you could get the property names using reflection). And thats it.

    Now you just have to make IsValidating = false and then when Save is requested show the errors with IsValidating = true.

    Other thing that you could do (and this would work on Silverlight 3) is bind the Visibility of the ValidationSummary to the IsValidating property (using a IValueConverter), and then control this from the ViewModel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Silverlight app using the MVVM pattern. My ViewModel currently consists
i am working on MVVM and using commanding in silverlight(DelegateEvent and ICommand) I want
I finally got validation working with MVVM in my Silverlight app. Now I'm wondering
I've been working in Silverlight recently and I've slowly been discovering that as simple
I am working on a silverlight app that you need to enter information into
I'm working on a Silverlight control that will allow multi-file downloading. At the moment
I'm working on a Silverlight Project with all the features and limitations that entails.
I'm working on a WPF application, and I'm structuring it using the MVVM pattern.
First time poster. I'm using MVVM-Light with Silverlight 4 and RIA Services. This has
I am working on a tool that will test the server of a Silverlight

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.