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. Image for the cookie policy date
close icon

Using SfTextBoxExt Data Validaton with Prism MVVM

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?

7 Replies

VJ Victory Jessie Selvam D Syncfusion Team February 27, 2015 12:25 PM UTC

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 February 27, 2015 04:49 PM UTC

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 February 27, 2015 06:25 PM UTC

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 March 1, 2015 04:37 PM UTC

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


VJ Victory Jessie Selvam D Syncfusion Team March 2, 2015 07:36 AM UTC

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 May 4, 2015 01:23 PM UTC

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


SC Saranya CJ Syncfusion Team May 5, 2015 11:32 AM UTC

Hi Jurgen,

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

Regards,
Saranya

Loader.
Live Chat Icon For mobile
Up arrow icon