We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Using SfTextBoxExt Data Validaton with Prism MVVM

Thread ID:

Created:

Updated:

Platform:

Replies:

118340 Feb 26,2015 03:33 PM May 5,2015 07:32 AM WinRT 7
loading
Tags: SfTextBoxExt
Jürgen
Asked On February 26, 2015 03:33 PM

I'm using Prism for Windows Runtime in my phone app. A couple of SfTextBoxExt are bound to the corresponding properties in the page's ViewModel. The PageViewModel derives from Prism's ViewModel and BindableBase, which implements INotifyPropertyChanged. The data bound properties are defined in the ViewModel like this:

public string Name {
    get { return _name; }
    set {
         _name = value;
         OnPropertyChanged("Name");
         OnPropertyChanged("Error");
    }
 }

or:

private string _name;
public string Name {
    get { return _name; }
    set {
       SetProperty(ref _name, value);
       OnPropertyChanged("Name");
       OnPropertyChanged("Error");
   }
}

and in XAML:
 <sfInput:SfTextBoxExt x:Name="NameTextBox"
     Text="{Binding Name, Mode=TwoWay}"
     Margin="0,2,0,8"
     sfData:DataValidation.PropertyPath="Name"
     sfData:DataValidation.NotifyOnDataErrors="True" />

I'm getting some strange behavior with the validation. All fields are required to be non-empty, checked as in the example using

if (String.IsNullOrEmpty(Name)) {
    return "Name field is required.";
 }

1. initially, the textboxes are framed red (because empty) -> OK
2. when entering some text, the red border disappears -> OK
3. when removing the text again, the border turns red again -> OK
4. when putting the cursor in an empty (red-bordered) textbox, entering nothing (leaving the textbox empty), and then moving the cursor to another textbox then the red border disappears -> NOT OK

I'm not sure what's causing this, and I can't tell from the documentation. Does anyone have experience with this?

Victory Jessie Selvam D [Syncfusion]
Replied On February 27, 2015 07:25 AM

Hi Jurgen,

Thank you for contacting Syncfusion support.

We are unable to reproduce the reported issue "DataValidation is not proper while moving focus to next control". We suspect it could be an issue with your sample. Could you please ensure whether you have added the following codes properly in your sample? Still if your able to reproduce the issue, please get back to us with your sample so that we can proceed further to resolve your problem.

Code snippet:

XAML
<
syncfusion:SfTextBoxExt x:Name="NameTextBox"

     Text="{Binding Name, Mode=TwoWay}" Height="30" Width="250"

     Margin="20,2,0,8"

     sfData:DataValidation.PropertyPath="Name"

     sfData:DataValidation.NotifyOnDataErrors="True">

 </syncfusion:SfTextBoxExt>

           

 <syncfusion:SfTextBoxExt x:Name="TextBox"

     Text="{Binding FatherName, Mode=TwoWay}" Height="30" Width="250"

     Margin="20,2,0,8"

     sfData:DataValidation.PropertyPath="FatherName"

     sfData:DataValidation.NotifyOnDataErrors="True">

 </syncfusion:SfTextBoxExt>

C#

public class TextBoxExtProperties : NotificationObject, IDataValidation

    {

        private string name;

        public string Name

        {

            get { return name; }

            set { name = value;

                RaisePropertyChanged("Name");

                RaisePropertyChanged("Error"); }

        }

        private string fathername;

        public string FatherName

        {

            get { return fathername; }

            set

            {

                fathername = value;

                RaisePropertyChanged("FatherName");

                RaisePropertyChanged("Error");

            }

        }   

       

        public string Error

        {

            get

            {

                if (String.IsNullOrEmpty(Name))

                {

                    return "Name field required.";

                }

                if (String.IsNullOrEmpty(FatherName))

                {

                    return "Father Name field required.";

                }

               return "";

            }

        }

        public string this[string columnname]

        {

            get

            {

                switch (columnname)

                {

                    case "Name":

                        if (String.IsNullOrEmpty(Name))

                        {

                            return "Name field required.";

                        }

                        break;

                    case "FatherName":

                        if (String.IsNullOrEmpty(FatherName))

                        {

                            return "FatherName field required.";

                        }

                        break;

                }

                return "";

            }

        }

    }

Please let us know if you need further assistance on this.

Regards,
Jessie

Jürgen
Replied On February 27, 2015 11:49 AM

Hi Jessie.

Thanks for looking into this.  I have prepared a small demo project and attached it to this message.

Best regards,
-Jürgen

Attachment: TextBoxValidation_8eda5c36.zip

Jürgen
Replied On February 27, 2015 01:25 PM

HI again.

I played around with it a bit more. It does not work without Prism either, so that apparently has nothing to do with it.  I could make it work in my demo by replacing the Windows Universal control (which I was using) with the Windows Phone control. So this might be a bug in the universal version of the SfTextBoxExt?

Regards,
-Jürgen

Jürgen
Replied On March 1, 2015 11:37 AM

I encountered another issue with this phone control. Perhaps that can be set via some property but I haven't been able to find that.

As opposed to the standard TextBox, the content of the SfTextBoxExt can be dragged in all directions and snaps back into the original position when released. That can be rather irritating for the user when trying to scroll the page and single-line text inputs start moving instead. How can I turn this off?

Regards,
-Jürgen

Victory Jessie Selvam D [Syncfusion]
Replied On March 2, 2015 02:36 AM

Hi Jürgen,

Thank you for your update.

Query #1: I played around with it a bit more. It does not work without Prism either, so that apparently has nothing to do with it. I could make it work in my demo by replacing the Windows Universal control (which I was using) with the Windows Phone control. So this might be a bug in the universal version of the SfTextBoxExt?
We are able to reproduce the issue “DataValidation doesn’t works while leaving empty textbox” in SfTextBoxExt.Universal. We have created a new support incident for this query and kindly follow up with the incident as follows:

http://www.syncfusion.com/support/directtrac/incidents/136011

Query #2: As opposed to the standard TextBox, the content of the SfTextBoxExt can be dragged in all directions and snaps back into the original position when released. That can be rather irritating for the user when trying to scroll the page and single-line text inputs start moving instead. How can I turn this off?
The content dragging issue is caused by Scrollviewer which is present in SfTextBoxExt’s template. This behaviour can be restricted by setting ScrollViewer.VerticalScrollMode=”Disabled” & ScrollViewer.HorizontalScrollMode=”Disabled” for the SfTextBoxExt. We have modified your sample by setting these properties and please download it from the following link:

Sample: TextBoxValidation_8eda5c36.zip

Please let us know whether the provided sample meets your requirement or not.

Regards,
Jessie

Jürgen
Replied On May 4, 2015 09:23 AM

In order to conclude this discussion (for anyone else reading it), I add the information that the problem is corrected in version 13.1.0.26 of the Universal XAML controls.

Thank you.
-Jürgen

Saranya CJ [Syncfusion]
Replied On May 5, 2015 07:32 AM

Hi Jurgen,

Thank you for this information. Please let us know if you require any other assistance on this.

Regards,
Saranya

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;