Set foreground back to default color using csharp

            <TextBox Header="Name"
                     MinWidth="250"
                     Grid.ColumnSpan="2"
                     PlaceholderText="Your pet name"
                     Text="{x:Bind Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     Foreground="{x:Bind NameErrorsList.Count, 
                                         Mode=OneWay, 
                                         Converter={StaticResource ErrorListToForegroundConverter}}"/>

    public class ErrorListToForegroundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var errorCount = (int)value;
            return errorCount != 0 ? new SolidColorBrush(Colors.Yellow) : null;
        }
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }

My textbox is not turn back to default foreground when being input or focus
When lose focus and refocus again I apply the default foreground
I think the problem is in here
return errorCount != 0 ? new SolidColorBrush(Colors.Yellow) : null

when change the
null
to new SolidColorBrush(Colors.Green)
It react and turn green even when being focus
does anyone know how to set the textbox foreground back to default color using C# ?
Was this page helpful?