BooleanToValueConverter Class

Converts boolean values to custom values for WPF data binding.

public sealed class BooleanToValueConverter : IValueConverter

Example

<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

NameDescription
BooleanToValueConverter()

BooleanToValueConverter()

public BooleanToValueConverter()

No documentation is available.

Properties

NameDescription
FalseValueGets or sets the value to return when the input is false.
NullValueGets 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.
TrueValueGets or sets the value to return when the input is true.

Gets or sets the value to return when the input is false.

public object? FalseValue { get; set; }

Property value

object?

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.

public object? NullValue { get; set; }

Property value

object?

Gets or sets the value to return when the input is true.

public object? TrueValue { get; set; }

Property value

object?

Methods

NameDescription
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.cs
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo? culture)

Parameters

value object?
targetType Type
parameter object?
culture CultureInfo?

Returns

object?

ConvertBack(object?, Type, object?, CultureInfo?)

BooleanToValueConverter.cs

This method is not supported and always throws NotSupportedException.

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture)

Parameters

value object?
targetType Type
parameter object?
culture CultureInfo?

Returns

object?