UI Field Validation in WPF

UI field validation in WPF is a one of most important. Because when the field can't get the Specific class then it will get Error. So it better to create a CheckField()  for specific Button Event & there you can implement the method as:

/******************* A Button Event *****************/
         private void appointAddButton_Click(object sender, RoutedEventArgs e)
        {
            AddAppointmentInListView();


        }
     /************** Implement AddAppointmentInListView Method*****************/
        private void AddAppointmentInListView()
        {
            try
            {
                if (CheckField())
                {
                    EAppointment objAppointment = new EAppointment();
                    objAppointment.TrackNo = Convert.ToInt64(employeeTrackNoTextBox.Text);
                    objAppointment.InterviewId = Convert.ToInt64(employeeIdTextBox.Text);
                    objAppointment.AppointmentDate =  appointDateDateTimePicker.SelectedDate.Value;
                    List<EAppointment> listAppoint = new List<EAppointment>();
                    listAppoint.Add(objAppointment);
                    objAppointment.AppointList = listAppoint;
                    appointlistView.Items.Add(objAppointment);
                    
                }
                
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
  /************* Implement CheckField Method************/
 /********* Note that you should Declare raiseKeyUp as Global********
/******** private bool raiseKeyUp = true; ********/
     private bool CheckField()
        {
            if (employeeTrackNoTextBox.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please enter Track Number", "IEMS", MessageBoxButton.OK);
                this.raiseKeyUp = false;
                employeeTrackNoTextBox.Focus();
                return false;
            }
                             return true;
        }

  You can also Make your Validation Field more Glossy if you download the Code from the link:


                 http://www.codeproject.com/KB/WPF/wpfvalidation.aspx
                 http://www.codeproject.com/KB/WPF/RegexValidationInWPF.aspx

  Now see what happen in your validation. Enjoy......!!



Popular posts from this blog

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report