• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

How do I use validation in WPF

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
1 Solution
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

MarcoCastroAuthor Commented:
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}"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now