I have two text fields for the first name and second username, and I created a converter to change the background color of the text field when the text is equal to a specific line. The problem I am facing is that the text field will only be updated at runtime and not updated when I change the text to text field.
XAML:
<TextBox x:Name="forenameTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="1" Background="{Binding Staff,Converter ={StaticResource StaffNameToBackgroundColourConverter1}}" Text="{Binding Staff.Forename, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/> <Label Content="Surname:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/> <TextBox x:Name="surnameTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="2" Background="{Binding Staff,Converter={StaticResource StaffNameToBackgroundColourConverter1}}" Text="{Binding Staff.Surname, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
Converter Code:
public class StaffNameToBackgroundColourConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var staff = (Staff) value; if (staff.Forename == "Donald" && staff.Surname == "Duck") { return "Yellow"; } else { return "White"; } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value; } }
Correct text entry:

Incorrect text input - no change:

c # converter wpf xaml
Nigelmassey
source share