How do I use validation in WPF

Posted on 2009-12-29
Last Modified: 2013-11-12
How do I write this code?

  <tbl:TextBox x:Name="edNome" Grid.Row="2" Grid.Column="1"
    Text="{Binding Data.Description,
   // This is my question: ValidationRules syntax
    ValidationRules={StaticResource FieldCantBeNull},
    ElementName=window, Mode=OneWay}" />

  FieldCantBeNull is a ValidationRule. How is written if I use two validations in the same TextBox? I want to know write in a single line.

  This format is the Blend format. Is there a way to write the ValidationRule automaticaly in Blend? I found hwo to write a Converter by not a Validator.


  Marco Castro
Question by:MarcoCastro
    LVL 7

    Expert Comment

    When you need two rules - see code below.
    Both rules must be defined in code behind.
    This example comes from MSDN and are adopted by me.... Not tested.

        <Binding Path="Age" Source="{StaticResource ods}"
                 UpdateSourceTrigger="PropertyChanged" >
            <c:AgeRangeRule Min="21" Max="130"/>

    Open in new window


    Accepted Solution

    Isn't it possible to write this code in a single line? In this format:

    Text="{Binding Data.Description,
        ValidationRules={...I don´t know what comes here....},
        ElementName=window, Mode=OneWay}"

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now