I have a TextBox
which is bound to a IPAddress
property. For that I've implemented a IValueConverter
which tries to parse the string
of the TextBox
to a IPAddress
. When the conversion fails, a red border is automatically painted around the TextBox
, indicating that the given value is incorrect. That is working so far and like intended.
My question is if there is a way to get somehow this failed state of the conversion to bind it to a IsEnabled
property of a Button
. And all that in XAML.
Here the IValueConverter
:
public class IpAddressConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is IPAddress)
{
return ((IPAddress)value).ToString();
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string)
{
IPAddress ipAddress;
if (IPAddress.TryParse((string)value, out ipAddress))
{
return ipAddress;
}
}
return false;
}
}
EDIT: I have implemented logic to validate the input already. But because of the failed conversion, the property doesn't get updated. And that means the property still holds the "old" value, which is of course correct, but doesn't need to be validated.