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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:08:27+00:00 2026-05-24T11:08:27+00:00

I have several Validation Rules , also I am using MVVM . I have

  • 0

I have several Validation Rules , also I am using MVVM .

I have some “Save” button , and I want to enable in only when I don’t have any datagridrows validating my rules.

How I should do in my

        bool CanSaveChanges
        {
            get { return true; }
        }

The datagrid is binded to collection public ICollectionView Customers

Thanks for help.

  • 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-24T11:08:27+00:00Added an answer on May 24, 2026 at 11:08 am

    here a simple example of adding new customer screen , I’m validating the name and Tel.No, the button won’t be enabled until allPropertiesValid property set to true , which means all validations are passed

    View

    <Window FlowDirection="RightToLeft" x:Class="GlassStore.AddNewSpecialCustomer"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:local="clr-namespace:GlassStore.ViewModels"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="AddNewSpecialCustomer" Height="346" Width="463" WindowStartupLocation="CenterScreen">
    
    <Window.DataContext>
        <local:AddNewSpecialCustomerViewModel/>
    </Window.DataContext>
    <Grid Background="{DynamicResource NormalBrush}">
        <Button IsDefault="True" Command="{Binding Save}" Content="موافق" Height="39" HorizontalAlignment="Left" Margin="15,256,0,0" VerticalAlignment="Top" Width="76" />
        <Label Content="إسم العميل" Height="36" HorizontalAlignment="Left" Margin="12,12,0,0" VerticalAlignment="Top" Width="79" />
        <TextBox Text="{Binding specialCustomerName,Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,UpdateSourceTrigger=PropertyChanged}" Height="36" HorizontalAlignment="Left" Margin="111,12,0,0" VerticalAlignment="Top" Width="209" />
        <Label Content="المنطقة/المكان" Height="35" HorizontalAlignment="Left" Margin="12,67,0,0"  VerticalAlignment="Top" Width="94" />
        <TextBox Text="{Binding region}" Height="35" HorizontalAlignment="Left" Margin="111,67,0,0" VerticalAlignment="Top" Width="210" />
        <TextBox Text="{Binding tel,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,UpdateSourceTrigger=PropertyChanged}" Height="33" HorizontalAlignment="Left" Margin="111,119,0,0" VerticalAlignment="Top" Width="210" />
        <Label Content="رقم الهاتف " Height="33" HorizontalAlignment="Left" Margin="12,119,0,0"  VerticalAlignment="Top" Width="94" />
        <Button IsCancel="True" Content="إلغاء" Height="39" HorizontalAlignment="Left" Margin="128,256,0,0" VerticalAlignment="Top" Width="78" />
        <Label Content="{Binding errorMessage}" ToolTip="{Binding richMessage}" Foreground="{Binding messageColor}" Height="40" HorizontalAlignment="Left" Margin="12,182,0,0"  VerticalAlignment="Top" Width="412" />
    </Grid>
    </Window>
    

    ViewModel

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ComponentModel;
    using System.Windows.Input;
    using System.Windows.Media;
    namespace GlassStore.ViewModels
    {
    class AddNewSpecialCustomerViewModel:ViewModelBase,IDataErrorInfo
    {
        private String _errorMessage;
        private Brush _messageColor;
        private String _richMessage;
        private String _specialCustomerName;
        private String _region;
        private String _tel;
        private bool _allPropertiesValid;
        private Dictionary<string, bool> validProperties;
        private Commands.RelayCommand _save;
    
        public AddNewSpecialCustomerViewModel()
        {
    
            validProperties = new Dictionary<string, bool>();
            validProperties.Add("specialCustomerName",false);
            validProperties.Add("tel", false);
            allPropertiesValid = false;
    
        }
    
        public String richMessage
        {
    
            get { return _richMessage; }
            set
            {
                if (_richMessage != value)
                {
                    _richMessage = value;
                    OnPropertyChanged("richMessage");
                }
            }
        }
        public String errorMessage
        {
    
            get { return _errorMessage; }
            set
            {
                if (_errorMessage != value)
                {
                    _errorMessage = value;
                    OnPropertyChanged("errorMessage");
                }
            }
        }
    
        public Brush messageColor
        {
            get
            {
                return _messageColor;
            }
            set
            {
                if (_messageColor != value)
                {
                    _messageColor = value;
                    OnPropertyChanged("messageColor");
                }
    
            }
        }
    
        public bool allPropertiesValid
        {
    
            get { return _allPropertiesValid; }
            set
            {
                if (_allPropertiesValid != value)
                {
                    _allPropertiesValid = value;
                  OnPropertyChanged("allPropertiesValid");                   
                }
            }
        }
    
        public String specialCustomerName
        {
            get { return _specialCustomerName; }
            set
            {
                if (_specialCustomerName != value)
                {
                    _specialCustomerName = value;
                   OnPropertyChanged("specialCustomerName");
    
                }
            }
        }
    
        public ICommand Save
        {
            get
            {
                if (_save == null)
                {
                    _save = new Commands.RelayCommand(param => CanAddSpecialCustomer(), param => AddSpecialCustomer());
                }
    
                return _save;
            }
        }
    
    
    
        public String region
        {
            get { return _region; }
            set
            {
                if (_region != value)
                {
                    _region = value;
                    OnPropertyChanged("region");
    
                }
            }
        }
    
        public String tel
        {
            get { return _tel; }
            set
            {
                if (_tel != value)
                {
                    _tel = value;
                   OnPropertyChanged("tel");
                }
            }
        }
    
        private bool CanAddSpecialCustomer()
        {
            return allPropertiesValid;
        }
    
        private void AddSpecialCustomer()
        {
            try
            {
                GlassStoreBLL.SpecialCustomer spcustomer = new GlassStoreBLL.SpecialCustomer();
                spcustomer.name = specialCustomerName;
                spcustomer.region = region;
                spcustomer.telNo = Int64.Parse(tel);
                spcustomer.AddNewCustomer(spcustomer);
                errorMessage = "نـجـاح";
                messageColor = Brushes.Green;
                region = "";
                tel = "";
                specialCustomerName = "";
            }
            catch (Exception d)
            {
                errorMessage = "خطأ أثناء تسجيل العميل الخاص";
                richMessage = d.Message;
                messageColor = Brushes.Red;
            }
        }
    
    
        string IDataErrorInfo.Error
        {
            get { return null; }
        }
    
        string IDataErrorInfo.this[string columnName]
        {
            get
            {
                string error = String.Empty;
                switch (columnName)
                {
                    case "specialCustomerName":
                        error = validateSpecialCustomerName();
                        validProperties["specialCustomerName"] = String.IsNullOrEmpty(error) ? true : false;
                        validateProperties();
                        return error;
                    case "tel":
                        error = validateTel();
                        validProperties["tel"] = String.IsNullOrEmpty(error) ? true : false;
                        validateProperties();
                        return error;
                    default:
                        throw new ApplicationException("Wrong Property name being validated");
                }
            }
        }
    
        private string validateSpecialCustomerName()
        {
            if (String.IsNullOrEmpty(specialCustomerName))
            {
                return "يجب إدخال إسم العميل الخاص";
            }
            else
            {
                if (specialCustomerName.Length < 2) return "إسم العميل الخاص لا يمكن أن يكون حرفين";
            }
            return String.Empty;
        }
    
        private string validateTel()
        {
            int result;
            if (int.TryParse(tel, out result))
            {
                if (tel.Count() < 6)
                {
                    return "رقم التلفون لا يمكن أن يكون أقل من 6 أرقام";
                }
                else
                {
                    if (result < 0)
                    {
                        return "لا يمكن إدخال قيمة سالبة هنا";
                    }
                    return String.Empty;
                }
            }
            else
            {
                return "الرجاء إدخال أرقام فقط في رقم التلفون";
            }
    
        }
    
        private void validateProperties()
        {
            foreach (bool isValid in validProperties.Values)
            {
                if (isValid == false)
                {
                    allPropertiesValid = false;
                    return;
                }
            }
            allPropertiesValid = true;
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with several fields and using jQuery validation plugin. My input
I have several tables whose only unique data is a uniqueidentifier (a Guid) column.
We have several .NET applications that monitor a directory for new files, using FileSystemWatcher.
I have a form in which I am using remote validation to check if
I have a job that performs several validation checks on rows in several tables
I have started using jQuery Validation plugin 1.7. I have a wizard like interface
I have several user controls that contain a drop down list, various validation controls,
Using jQuery version 1.4.2 and Validation plugin version 1.8.1 I have a textbox that
I have several fields in my activity which all take integers, and integers only.
I have a form with several fields. I have separate validation checks for each

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.