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 7970165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:21:20+00:00 2026-06-04T07:21:20+00:00

I am stuck in a seemingly common requirement. I have a WPF Prism (for

  • 0

I am stuck in a seemingly common requirement. I have a WPF Prism (for MVVM) application. My model implements the IDataErrorInfo for validation. The IDataErrorInfo works great for non-numeric properties. However, for numeric properties, if the user enters invalid characters (which are not numeric), then the data doesn’t even reach the model because wpf cannot convert it to numeric type.

So, I had to use WPF ValidationRule to provide user some meaningful message for invalid numeric entries. All the buttons in the view are bound to DelegateCommand of prism (in view model) and the enabling/disabling of buttons is done in View Model itself.

Now if a wpf ValidationRule fail for some TextBox, how do I pass this information to View Model so that it can appropriately disable buttons in the view ?

  • 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-06-04T07:21:21+00:00Added an answer on June 4, 2026 at 7:21 am

    Nirvan

    The simplest way to solve this particular issue is to use a numeric textbox, which prevents the user from entering an invalid value (you can either do this via a Third Party Vendor, or find an open source solution, such as a class derived from Textbox that suppresses non numeric input).

    The second way to handle this in MVVM without doing the above, is to define another field in you ViewModel which is a string, and bind that field to your textbox. Then, in the setter of your string field you can set the Integer, and assign a value to your numeric field:

    Here is a rough example: (NOTE I did not test it, but it should give you the idea)

    // original field
    private int _age;
    int Age 
    {
       get { return _age; }
       set { 
         _age = value; 
         RaisePropertyChanged("Age");
       }
    }
    
    
    private string _ageStr;
    string AgeStr
    {
       get { return _ageStr; }
       set { 
         _ageStr = value; 
         RaisePropertyChanged("AgeStr");
         if (!String.IsNullOrEmpty(AgeStr) && IsNumeric(AgeStr) )
             Age = intVal;
        }
    } 
    
    private bool IsNumeric(string numStr)
    {
       int intVal;
       return int.TryParse(AgeStr, out intVal);
    }
    
    #region IDataErrorInfo Members
    
    public string this[string columnName]
    {
        get
        {
            
            if (columnName == "AgeStr" && !IsNumeric(AgeStr)
               return "Age must be numeric";
        }
    }
    
    #endregion
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kinda stuck here... I have an application with lets say 5000 rows of data
I stuck with problem of mail application , i am developing a website for
I'm stuck with a seemingly very simple app that I'm trying to develop Basically,
It must be an afternoon caffeine deprivation... stuck on a seemingly simple logic. I
I'm stuck on a RegEx problem that's seemingly very simple and yet I can't
I'm stumped by a seemingly simple problem. In my ASP.NET page, I have a
I have a (seemingly) simple question to read in a string and print it
Stuck with this particular issue. I have code that get lots of pages from
Possible Duplicate: WPF: XAML property declarations not being set via Setters? I am stuck
I'm using the Last.fm API and I stuck on something seemingly fairly simple. One

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.