What is the simplest way in WPF to enable a Button when the user types something into a TextBox?
IF you were not using Commands, another alternative is using a Converter.
For example, using a generic Int to Bool converter:
[ValueConversion(typeof(int), typeof(bool))]
public class IntToBoolConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
return (System.Convert.ToInt32(value) > 0);
}
catch (InvalidCastException)
{
return DependencyProperty.UnsetValue;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return System.Convert.ToBoolean(value) ? 1 : 0;
}
#endregion
}
Then on the buttons IsEnabled property:
HTH,
Dennis