Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Validation Messages [modified]

Validation Messages [modified]

Scheduled Pinned Locked Moved WPF
helpcom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tripathi Swati
    wrote on last edited by
    #1

    I have implemented validation using IDialogService on INotifyPropertyChanged but its not working properly when i click on save button and after successfull insertion if i ll clear my control then also my validation message display error message. if any boday can help me then i ll be thankfull to him.

    Reasons are not Important but Results are Important. http://www.sql4professional.blogspot.com Swati Tripathi

    modified on Saturday, May 22, 2010 5:35 AM

    A 1 Reply Last reply
    0
    • T Tripathi Swati

      I have implemented validation using IDialogService on INotifyPropertyChanged but its not working properly when i click on save button and after successfull insertion if i ll clear my control then also my validation message display error message. if any boday can help me then i ll be thankfull to him.

      Reasons are not Important but Results are Important. http://www.sql4professional.blogspot.com Swati Tripathi

      modified on Saturday, May 22, 2010 5:35 AM

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      You need to post code here to show what you have implemented so far before anyone can help you.

      My signature "sucks" today

      T 1 Reply Last reply
      0
      • A Abhinav S

        You need to post code here to show what you have implemented so far before anyone can help you.

        My signature "sucks" today

        T Offline
        T Offline
        Tripathi Swati
        wrote on last edited by
        #3

        below is used for binding validation

        <TextBox x:Name="txtDispalyName" Text="{Binding Path=DisplayName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" Grid.Row="1" Height="24" LostFocus="txtDispalyName_LostFocus" Grid.Column="2" Margin="18,2,54,0" VerticalAlignment="Top" TabIndex="0" >

        while in code behind on save click i m calling below code

        ViewModel.IsError = true;
        getBindProperty();
        if (ViewModel.Save())
        {
        IsSaveClose = true;
        SaveData();

        }
        else
        {
        ViewModel._dialogService.DisplayValidationDialog(ViewModel.Errors);
        }

        while my validation class is

        public class MyViewModel : INotifyPropertyChanged
        {
        public readonly IDialogService _dialogService;
        CultureInfo Culture;
        public MyViewModel(IDialogService dialogService)
        {
        _dialogService = dialogService;
        }

            private string \_displayName = "";
             
        
            public bool  IsError { get; set; }
            
            
        
            public string DisplayName
            {
                get { return \_displayName ; }
                set
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        Culture = Thread.CurrentThread.CurrentCulture;
                        IsError = false;
                        throw new Exception(Erp3s.Resources.Strings.ResourceManager.GetString("Display Name is required",Culture));
        
                    }
                    \_displayName = value;
                    OnPropertyChanged("DisplayName");
                }
            }
        
          
        
        
            private readonly ObservableCollection<ValidationError> \_errors = new ObservableCollection<ValidationError>();
        
            public ObservableCollection<ValidationError> Errors
            {
                get { return \_errors; }
            }
        
            public bool IsViewStateValid()
            {
                return Errors.Count == 0;
            }
        
            public bool Save()
            {
        
                         
                
                
             if (!this.IsViewStateValid())
                {
                    return false; 
                  //\_dialogService.DisplayValidationDialog(Errors);
                }
                else
                {
                    return true;
                }
            }
        
            public event PropertyChangedEventHandler PropertyChanged;
        
            protected virtual void OnPropertyChanged(string propertyName)
            {
                PropertyChangedEventHand
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups