TXTextControl.WPF.ColorConverter Class

The WPF.ColorConverter class provides a way to convert a System.Drawing.Color value to System.Windows.Media.Color value. With this converter a property with a System.Drawing.Color type can be used in a XAML data binding.

Introduced: 16.0.

Syntax

[C#]
[ValueConversion(typeof(System.Drawing.Color), typeof(System.Windows.Media.Color))]
public class ColorConverter : IValueConverter
[Visual Basic]
Public Class ColorConverter
  Implements IValueConverter

Methods

Method Description
Convert Converts a System.Drawing.Color value to System.Windows.Media.Color value.
ConvertBack Converts a System.Windows.Media.Color to a System.Drawing.Color value.

Example

The following XAML example shows how to bind the InputFormat.TextColor property to the fill color of a rectangle using the ColorConverter class.

…
xmlns:tx="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
…
<Window.Resources>
    <tx:ColorConverter x:Key="colorConv" />
</Window.Resources>
…
<Rectangle
    Width="20"
    Height="20">
    <Rectangle.Fill>
        <SolidColorBrush
            Color="{Binding
                ElementName=textControl1,
                Path=InputFormat.TextColor,
                Converter={StaticResource colorConv}}" />
    </Rectangle.Fill>
</Rectangle>

See Also