tags:

views:

35

answers:

2

Hello... How can i add validation to a textbox that isnt bound ...

 <TextBox BorderThickness="1" Grid.Column="1" HorizontalAlignment="Stretch" Margin="3" x:Name="txtbFirstName" VerticalAlignment="Center" >
                            <TextBox.Text>
                                <Binding  >
                                    <Binding.ValidationRules>
                                        <local:validator Max="999.99" />
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>

doenst work

+1  A: 

You may try using a ValueConverter instead, which will provide you more extensibility.

Siva Gopal
would it work ? It must be bound somewhere..
Parhs
No need to be bound. Please don't forget to mark as answer, if it help you fix the problem. :-)
Siva Gopal
it doenst work if i dont specify a binding..
Parhs
I think, you needn't specify any property binding but you need to bind the converter to the textbox.
Siva Gopal
+1  A: 

You could just bind the Text property to itself.

<TextBox>
    <TextBox.Text>
        <Binding  Path="Text" RelativeSource="{RelativeSource Self}">
            <Binding.ValidationRules>
                <local:Validator Max="999.99" />
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>
karmicpuppet
thank you :) now it is too late. Tried that but didnt put path="text" and ofcource nothing worked..I have 1 week experience with WPF
Parhs