BooleanToValueConverter Class
Converts boolean values to custom values for WPF data binding.
public sealed class BooleanToValueConverter : IValueConverterExample
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:Meziantou.Framework.WPF;assembly=Meziantou.Framework.WPF">
<UserControl.Resources>
<wpf:BooleanToValueConverter x:Key="BoolToVisibility" TrueValue="{x:Static Visibility.Visible}" FalseValue="{x:Static Visibility.Collapsed}" />
</UserControl.Resources>
<TextBlock Text="Shown when IsEnabled is true" Visibility="{Binding IsEnabled, Converter={StaticResource BoolToVisibility}}" />
</UserControl>- Implements
Constructors
| Name | Description |
|---|---|
| BooleanToValueConverter() |
BooleanToValueConverter()
public BooleanToValueConverter()No documentation is available.
Properties
| Name | Description |
|---|---|
| FalseValue | Gets or sets the value to return when the input is false. |
| NullValue | Gets or sets the value to return when the input is null or cannot be converted to a boolean. If not set, BooleanToValueConverter.FalseValue is used instead. |
| TrueValue | Gets or sets the value to return when the input is true. |
FalseValue
BooleanToValueConverter.csNullValue
BooleanToValueConverter.csGets or sets the value to return when the input is null or cannot be converted to a boolean. If not set, BooleanToValueConverter.FalseValue is used instead.
public object? NullValue { get; set; }Property value
TrueValue
BooleanToValueConverter.csMethods
| Name | Description |
|---|---|
| Convert(object?, Type, object?, CultureInfo?) | Converts a value to the corresponding BooleanToValueConverter.TrueValue or BooleanToValueConverter.FalseValue. |
| ConvertBack(object?, Type, object?, CultureInfo?) | This method is not supported and always throws NotSupportedException. |
Convert(object?, Type, object?, CultureInfo?)
BooleanToValueConverter.csConverts a value to the corresponding BooleanToValueConverter.TrueValue or BooleanToValueConverter.FalseValue.
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo? culture)ConvertBack(object?, Type, object?, CultureInfo?)
BooleanToValueConverter.csThis method is not supported and always throws NotSupportedException.
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture)