none
And again about Validation Rule

    Question

  • Good day

    I'm already read many articles about validation rules, but....
    Before this case I use ValidationRule in custom form or inside UserControl which also hosted on form.

    At this moment I need something more complex. One of the product (SCSM) has an ability to add another UserControls dynamically. SCSM has a hosted from, inside that form placed UserControl (also belong to SCSM). That control read the config data from XML and create other controls listed in config file. I don't know exactly the moment then it create the controls: at load or inside consctructor.

    After that we get visual tree look like that (simplified):

    Form
    |
    |->UserControl (SCSM)
               |
               |-> UserControl (my)

    Problem: my custom UserControl never run validation rule then form opened first time.

    For example, I have a TextBox inside of my UserControl. Text property of the TextBox bind to some property in DataContext. To binding added validation rule (simple validation rule, I'm already check my own rules and standard rules with same result). That rule check if value is empty. Then form with my control is opened validation not fired. If I type something inside of control and then delete validation rule fired.

    I"m already try to use "((Control)sender).GetBindingExpression(TextBox.TextProperty).UpdateSource()" in Loaded event handler of TextBox (if I add this to LostFocus then validation also working).

    Any idea how to make validation work on form loaded?


    http://freemanru.wordpress.com/ freemanru (at) gmail (dot) com
    Friday, August 12, 2011 7:39 PM

Answers

All replies

  • Ok

    To make thinks clear for me, I tri to describe the situation and you correct me if I get wrong in some or the hole issue

    Control1 -> has Textbox1 (text must be validated)

                 |

                 --->  Control2(child) -> has Textbox2 (text must be validated)

                      |

                      --->  Control3(child) -> has Textbox3 (text must be validated)

                     ....................

                                |

                                --->  ControlN(child) -> has TextboxN (text must be validated)

    Your problem is to provide a validation mecanism for all the children and that validation mecanism propagates from the top to the bottom

    Reguards


    The complexity resides in the simplicity Follow me at: http://smartssolutions.blogspot.com
    Friday, August 12, 2011 8:30 PM
  • Not exaclly. I need validate control then form opened first time and property already has wrong value (empty in my case).
    http://freemanru.wordpress.com/ freemanru (at) gmail (dot) com
    Friday, August 12, 2011 8:33 PM
  • Hi Anton Gritsenko,

    You can set the ValidationRule's ValidatesOnTargetUpdated property to True. Then the validtion also happens when the binding updates your target, which happens when your form loads.

    Hope this helps.

    Best regards,

     


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 16, 2011 7:39 AM
    Moderator
  • Great, thnks a lot!!
    http://freemanru.wordpress.com/ freemanru (at) gmail (dot) com
    Tuesday, August 16, 2011 8:27 AM