Back to Skills

using-converter-markup-extension

verified

Implements IValueConverter as MarkupExtension for direct XAML usage without StaticResource. Use when creating converters to eliminate resource dictionary declarations.

View on GitHub

Marketplace

dotnet-claude-plugins

christian289/dotnet-with-claudecode

Plugin

wpf-dev-pack

development

Repository

christian289/dotnet-with-claudecode
5stars

wpf-dev-pack/skills/using-converter-markup-extension/SKILL.md

Last Verified

January 23, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/christian289/dotnet-with-claudecode/blob/main/wpf-dev-pack/skills/using-converter-markup-extension/SKILL.md -a claude-code --skill using-converter-markup-extension

Installation paths:

Claude
.claude/skills/using-converter-markup-extension/
Powered by add-skill CLI

Instructions

# Using Converter Markup Extension

Combine `MarkupExtension` with `IValueConverter` for direct XAML usage without resource declarations.

## Why Markup Extension Converters?

| Aspect | StaticResource Converter | MarkupExtension Converter |
|--------|-------------------------|--------------------------|
| Declaration | Required in Resources | Not required |
| XAML Usage | `{StaticResource MyConverter}` | `{local:MyConverter}` |
| Singleton | Manual implementation | Built-in lazy singleton |
| Boilerplate | More | Less |

---

## Base Classes

### IValueConverter Base (.NET 7+)

```csharp
namespace MyApp.Converters;

public abstract class ConverterMarkupExtension<T> : MarkupExtension, IValueConverter
    where T : class, new()
{
    private static readonly Lazy<T> _converter = new(() => new T());

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return _converter.Value;
    }

    public abstract object? Convert(
        object? value,
        Type targetType,
        object? parameter,
        CultureInfo culture);

    public virtual object? ConvertBack(
        object? value,
        Type targetType,
        object? parameter,
        CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}
```

### IMultiValueConverter Base

```csharp
namespace MyApp.Converters;

public abstract class MultiConverterMarkupExtension<T> : MarkupExtension, IMultiValueConverter
    where T : class, new()
{
    private static readonly Lazy<T> _converter = new(() => new T());

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return _converter.Value;
    }

    public abstract object? Convert(
        object?[] values,
        Type targetType,
        object? parameter,
        CultureInfo culture);

    public virtual object?[] ConvertBack(
        object? value,
        Type[] targetTypes,
        object? parameter,
        CultureInfo culture)
    {
        throw new NotSupportedExcepti

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5204 chars