I have a textbox with a TextChanged trigger.
However, every time the event triggers, the Min and Max value used in the method is what the value was prior to the change. For example, if Min was 5 and Max was 10, and I change Max to 1, the value that gets passed to the method is 5 and 10 for the Min and Max value, as opposed to 5 and 1.
If I change Max back to 10, the values that get passed is 5 and 1, instead of 5 and 10.
How can I fix this? Any help is greatly appreciated!
Textboxes:
<TextBox Grid.Row="2" Grid.Column="1" TextChanged="minMaxValidator" Name="MinValueTextBox"
Text="{Binding Path=Point.MinValue}">
</TextBox>
<TextBox Grid.Row="3" Grid.Column="1" TextChanged="minMaxValidator" Name="MaxValueTextBox"
Text="{Binding Path=Point.MaxValue}">
</TextBox>
Behind:
private void minMaxValidator(object sender, TextChangedEventArgs args)
{
if (Point.MinValue > Point.MaxValue)
{
MinValueTextBox.Background = Brushes.Red;
MaxValueTextBox.Background = Brushes.Red;
}
else
{
MinValueTextBox.Background = Brushes.Transparent;
MaxValueTextBox.Background = Brushes.Transparent;
}
}
Found out that adding
UpdateSourceTrigger=PropertyChangedto the Binding resolved this issue. Like so: