TX Text Control .NET for WPF

BooleanConverter Class

Class|Introduced in 16.0
Namespace
TXTextControl.WPF
Package
TXTextControl.TextControl.WPF.SDK from the private NuGet feed or Text Control Offline Packages
Assembly
TXTextControl.WPF.dll
Install
dotnet add package TXTextControl.TextControl.WPF.SDK .NET 8 and later. For .NET Framework, reference TXTextControl.WPF.dll from the setup.
Implements
IValueConverter

Description

The BooleanConverter class provides a way to convert a value to a boolean value. The converter returns true when the specified parameter is the string representation of the value. This is useful with data binding to place a checkmark in menus or to check or uncheck a toggle button. The class can be used in XAML as a static resource to automatically convert bound property values. Supported types are: System.Enum, int, int?, bool?, char and char?.

Syntax

public class BooleanConverter : IValueConverter

Examples

The following XAML example shows how to bind radio buttons to the InputFormat.NumberedListFormat property using the BooleanConverter class and the InputFormat.NumberFormats property.

…
xmlns:tx="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
…
<Window.Resources>
    <tx:BooleanConverter x:Key="boolConv" />
</Window.Resources>
…
<RadioButton
    Content="{Binding ElementName=textControl1, Path=InputFormat.NumberFormats[0]}"
    GroupName="numberFormat"
    IsChecked="{Binding
        ElementName=textControl1,
        Path=InputFormat.NumberedListFormat,
        Converter={StaticResource boolConv},
        ConverterParameter=ArabicNumbers}" />
<RadioButton
    Content="{Binding ElementName=textControl1, Path=InputFormat.NumberFormats[1]}"
    GroupName="numberFormat"
    IsChecked="{Binding
        ElementName=textControl1,
        Path=InputFormat.NumberedListFormat,
        Converter={StaticResource boolConv},
        ConverterParameter=Letters}" />
…

The following example creates a Boolean Converter instance for a document-processing operation. The created object is then available to the surrounding document workflow.

TXTextControl.WPF.BooleanConverter booleanConverter = new();
Console.WriteLine("Boolean Converter is ready for use.");

Members

Constructors

ConstructorDescription
BooleanConverterNot described in the reference. public BooleanConverter();

Methods

MethodDescription
ConvertConverts a value to a boolean. True is returned, if the specified parameter is the string representation of value.
ConvertBackConverts a boolean to a value of the type specified through the targetType parameter.