# 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.

- **Product:** TX Text Control .NET for WPF
- **Section:** Reference
- **Kind:** Class
- **Introduced:** 16.0
- **Namespace:** `TXTextControl.WPF`
- **Package:** `TXTextControl.TextControl.WPF.SDK` (assembly `TXTextControl.WPF.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.WPF.dll` from the setup
- **Implements:** `System.Windows.Data.IValueConverter`
- **Path:** TX Text Control .NET for WPF > Reference > TXTextControl.WPF > ColorConverter Class
- **652 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/llms-full.txt

---

### Description

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.

### Syntax

```csharp
public class ColorConverter : IValueConverter
```

```vbnet
Public Class ColorConverter
    Implements IValueConverter
```

### Examples

The following XAML example shows how to bind the [InputFormat.TextColor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/textcolor-property/llms-full.txt) property to the fill color of a rectangle using the ColorConverter class.

```plaintext
…
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>
```

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

```csharp
TXTextControl.WPF.ColorConverter colorConverter = new();
Console.WriteLine("Color Converter is ready for use.");
```

```vbnet
Dim colorConverter As New TXTextControl.WPF.ColorConverter()
Console.WriteLine("Color Converter is ready for use.")
```

---

## In This Section

- [ColorConverter.Convert Method](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/convert-method/llms-full.txt): Converts a System.Drawing.Color value to System.Windows.Media.Color value.
- [ColorConverter.ConvertBack Method](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/convertback-method/llms-full.txt): Converts a System.Windows.Media.Color to a System.Drawing.Color value.

---

## Nearby

- **Previous:** [ButtonBar.ButtonBarItem Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/buttonbar/buttonbaritem-enumeration/llms-full.txt)
- **Next:** [ColorConverter.Convert Method](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/convert-method/llms-full.txt)
