BooleanConverter Class
- Namespace
TXTextControl.WPF
- Package
TXTextControl.from the private NuGet feed or Text Control Offline PackagesTextControl. WPF. SDK
- Assembly
TXTextControl.WPF. dll
- Install
dotnet add package TXTextControl..NET 8 and later. For .NET Framework, referenceTextControl. WPF. SDK TXTextControl.from the setup.WPF. dll
- Implements
- IValue
Converter
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 : IValueConverterPublic Class BooleanConverter
Implements IValueConverterExamples
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.");Dim booleanConverter As New TXTextControl.WPF.BooleanConverter()
Console.WriteLine("Boolean Converter is ready for use.")Members
Constructors
| Constructor | Description |
|---|---|
| BooleanConverter | Not described in the reference. public BooleanConverter(); |
Methods
| Method | Description |
|---|---|
| Convert | Converts a value to a boolean. True is returned, if the specified parameter is the string representation of value. |
| ConvertBack | Converts a boolean to a value of the type specified through the targetType parameter. |