I have text field that binding with int property ProductPrice and button that is disabled if I put in textbox some wrong data (e.g. number that <= 0):
<TextBox Grid.Row="4" Grid.Column="2"
Text="{Binding ProductPrice, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}"/>
<Button HorizontalAlignment="Right" Command="{Binding Path=DataContext.AddProductCommand,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
Margin="2" Width="60" Grid.Row="6" Grid.Column="2" Content="Add" />
But if I put in textbox some text then button is not disabled. I think it because property ProductPrice is not changed because was generate some exception. Herewith validation work normal. What should I do?
Try to set
{Binding ProductPrice Mode=TwoWay}BTW, which exception are thrown?
EDIT: Answer to the comments
I see two options which you are have:
string ProductPriceValueproperty (under the cover use original one ofinttype) and bind textbox to itIValueConverterand use it in bindingJust wondering why you’re not using
doubletype forProductPriceproperty