locked
Custom Validation of a Textbox RRS feed

  • Question

  • I have an app where I want to validate the data in a text box. The valid values change based on the date as per the following function I wrote:

            public static void SetMinSITDiscount(Estimate Est)
            {
                if (Est.SITDiscount.HasValue)
                {
                    if (Est.OrgState.ToUpper() == "AL" && Est.DestState.ToUpper() == "AL")
                    {
                        Est.Discount = 0;
                    }
                    else if (Est.PUDate >= new DateTime(2011, 05, 1))
                    {
                        if (Est.SITDiscount > 25)
                            Est.SITDiscount = 25;
                    }
                    else if (Est.PUDate >= new DateTime(2010, 8, 1) && Est.MoveType.ToUpper() == "INTERSTATE")
                    {
                        if (Est.SITDiscount > 50)
                            Est.SITDiscount = 50;
                    }
                    else if (Est.PUDate >= new DateTime(2008, 9, 1))
                    {
                        if (Est.SITDiscount > 30)
                            Est.SITDiscount = 30;
                    }
                    else if (Est.PUDate >= new DateTime(2008, 2, 1))
                    {
                        if (Est.SITDiscount > 20)
                            Est.SITDiscount = 20;
                    }
                }
            }
    

    The original idea was to call this function in the LostFocus event.  Estimate is a class that is created from a Service Reference Entity.  I bind the properties of that object to the fields in the xaml page.  The problem is that it doesn't push the data back to the Est object until after the LostFocus event fires.  Is there a way to check the data after it is saved back to the Est object?

    Jim


    Jim Wilcox

    Thursday, November 7, 2013 10:44 PM

Answers

  • Hi Jim,

    Could I understand the scenario like this: You bind the Est object to the xaml page, and the source of the Est obj comes from the text box, now you call the function you posted while the text box LostFocus event fires. But I could not understand what you mean by "Is there a way to check the data after it is saved back to the Est object".

    Let's say if you binding the Est object to the xaml page, you could always use Binding Converter property, when you Est object is ready and binding to the xaml page, it will firstly fire the convert action and binding the result returned by convert function to the xaml page.

    Is this what you need or could you tell me more what you want to do.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, November 8, 2013 2:31 AM
    Moderator
  • Hey James,

    Thanks for your reply.

    I am actually using a converter in the binding since the value in the Est entity is a float.  Putting breakpoints in the Converter is how I can tell that the LostFocus event is occurring before the data is updated to the Est entity.  I tried using the ConverterParamter to pass the Est entity to the Converter, but you can't bind to ConverterParamter in the XAML so that won't work.  My original goal was to follow a guidline I learned in a Channel 9 video which suggested keeping your business logic separate from your code behind files.  Since I need some fields on the screen to react to values in other fields, this is proving to be impossible.  I will mark you as the answer since you responded.

    Thanks,

    Jim


    Jim Wilcox

    Friday, November 8, 2013 4:36 PM

All replies

  • Hi Jim,

    Could I understand the scenario like this: You bind the Est object to the xaml page, and the source of the Est obj comes from the text box, now you call the function you posted while the text box LostFocus event fires. But I could not understand what you mean by "Is there a way to check the data after it is saved back to the Est object".

    Let's say if you binding the Est object to the xaml page, you could always use Binding Converter property, when you Est object is ready and binding to the xaml page, it will firstly fire the convert action and binding the result returned by convert function to the xaml page.

    Is this what you need or could you tell me more what you want to do.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, November 8, 2013 2:31 AM
    Moderator
  • Hey James,

    Thanks for your reply.

    I am actually using a converter in the binding since the value in the Est entity is a float.  Putting breakpoints in the Converter is how I can tell that the LostFocus event is occurring before the data is updated to the Est entity.  I tried using the ConverterParamter to pass the Est entity to the Converter, but you can't bind to ConverterParamter in the XAML so that won't work.  My original goal was to follow a guidline I learned in a Channel 9 video which suggested keeping your business logic separate from your code behind files.  Since I need some fields on the screen to react to values in other fields, this is proving to be impossible.  I will mark you as the answer since you responded.

    Thanks,

    Jim


    Jim Wilcox

    Friday, November 8, 2013 4:36 PM