Thursday, April 28, 2011

WPF Validating unbound textbox

Hello, is it possible to use validation without the Binding part? The thing is my textbox is not bound to any object, but I still want to validate it's content. The only way I've found so far is this:

 <TextBox Grid.Row="0" Grid.Column="1" MaxLength="50" x:Name="textBoxTubeName" Margin="5,5,0,5">
  <TextBox.Text>
   <Binding Path="Name" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" NotifyOnValidationError="True">
    <Binding.ValidationRules>
     <validation:InvalidCharactersRule />
    </Binding.ValidationRules>
   </Binding>
  </TextBox.Text>
 </TextBox>

But again, it only works when the TextBox.Text is bound to something (in this case, the Name property), how would I go about this without binding?

Thanks!

From stackoverflow
  • According to the MSDN forums it's not possible yet but it is planned (Note: this is an old post). However, I still can't find a way to do it so it may not be implemented yet.

    Carlo : Yeah, I think I'm going to have to do the code myself. I think Microsoft idea to concentrate on binding is good, but limiting the validation this way due to that purpose, is not so good. Thanks Lucas.
    Lucas McCoy : @Carlo: Totally agreed.

0 comments:

Post a Comment