In this Post we are going to see how to create a converter in WPF, we are going to disable a button based on input, for this we are going to convert the bool to Visibility type.
Converter:
Binding Converter to Xaml
From this post you can learn how to create a converter in WPf
Converter:
class EdittoVisiblityConvertor : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
bool val;
bool.TryParse(value.ToString(), out val);
if (val)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Binding Converter to Xaml
<Button Content="Save" Command="{Binding SaveCommand}"
Visibility="{Binding EditMode ,
Converter={StaticResource EditConvertor}}"
Width="75"></Button>
From this post you can learn how to create a converter in WPf
No comments:
Post a Comment