make-wpf-converter
Generates WPF IValueConverter or IMultiValueConverter classes with MarkupExtension pattern. Use when creating a new value converter, scaffolding a MultiValueConverter, or adding a converter with direct XAML usage. Usage: /wpf-dev-pack:make-wpf-converter <ConverterName> [multi]
What this skill does
# WPF Converter Generator
**If `$0` is empty, use the AskUserQuestion tool to ask: "Enter the Converter name (e.g., BoolToVisibility, NullToVisibility)". Do NOT proceed until a valid name is provided. Use the response as the ConverterName for all subsequent steps.**
Generate a `$0Converter` class with MarkupExtension pattern for direct XAML usage.
If `multi` is appended to the arguments, generate IMultiValueConverter instead of IValueConverter.
- Replace `{Namespace}` with the project's root namespace detected from csproj or existing code.
- Replace `{SourceType}` and `{TargetType}` with the appropriate types based on the converter name (e.g., BoolToVisibility → bool, Visibility).
- Replace `{Project}` with the target project path.
## Usage
```bash
# IValueConverter
/wpf-dev-pack:make-wpf-converter BoolToVisibility
# IMultiValueConverter
/wpf-dev-pack:make-wpf-converter AllTrue multi
```
---
## Generated Code
### Base Class (ConverterMarkupExtension.cs)
Create this base class first in your Converters folder:
```csharp
namespace {Namespace}.Converters;
/// <summary>
/// Base class for converters that can be used directly in XAML without resource declaration.
/// </summary>
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("ConvertBack is not supported.");
}
}
```
### Base Class (MultiConverterMarkupExtension.cs)
```csharp
namespace {Namespace}.Converters;
/// <summary>
/// Base class for multi-value converters with MarkupExtension support.
/// </summary>
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 NotSupportedException("ConvertBack is not supported.");
}
}
```
---
### IValueConverter
```csharp
namespace {Namespace}.Converters;
/// <summary>
/// Converts {SourceType} to {TargetType}.
/// </summary>
public sealed class $0Converter : ConverterMarkupExtension<$0Converter>
{
public override object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture)
{
// TODO: Implement conversion logic
if (value is not {SourceType} source)
{
return DependencyProperty.UnsetValue;
}
return source; // Replace with actual conversion
}
}
```
### IMultiValueConverter
```csharp
namespace {Namespace}.Converters;
/// <summary>
/// Combines multiple values into a single result.
/// </summary>
public sealed class $0Converter : MultiConverterMarkupExtension<$0Converter>
{
public override object? Convert(
object?[] values,
Type targetType,
object? parameter,
CultureInfo culture)
{
// Validate input values
if (values is null || values.Length < 2)
{
return DependencyProperty.UnsetValue;
}
// Check for unset values
if (values.Any(v => v == DependencyProperty.UnsetValue))
{
return DependencyProperty.UnsetValue;
}
// TODO: Implement multi-value conversion logic
return values;
}
}
```
---
## XAML Usage
### MarkupExtension Pattern (Recommended)
```xml
<Window xmlns:conv="clr-namespace:MyApp.Converters">
<!-- No resource declaration needed! -->
<TextBlock Visibility="{Binding IsVisible, Converter={conv:BoolToVisibilityConverter}}"/>
<!-- With parameter -->
<TextBlock Visibility="{Binding IsHidden, Converter={conv:BoolToVisibilityConverter}, ConverterParameter=Invert}"/>
</Window>
```
### MultiBinding
```xml
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{conv:FullNameConverter}">
<Binding Path="FirstName"/>
<Binding Path="LastName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
```
---
## Common Converters
### BoolToVisibilityConverter
```csharp
public sealed class BoolToVisibilityConverter : ConverterMarkupExtension<BoolToVisibilityConverter>
{
public override object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture)
{
if (value is not bool boolValue)
return Visibility.Collapsed;
var invert = parameter is "Invert" or "invert";
return (boolValue ^ invert) ? Visibility.Visible : Visibility.Collapsed;
}
}
```
### NullToVisibilityConverter
```csharp
public sealed class NullToVisibilityConverter : ConverterMarkupExtension<NullToVisibilityConverter>
{
public override object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture)
{
var isNull = value is null;
var invert = parameter is "Invert";
return (isNull ^ invert) ? Visibility.Collapsed : Visibility.Visible;
}
}
```
### InverseBoolConverter
```csharp
public sealed class InverseBoolConverter : ConverterMarkupExtension<InverseBoolConverter>
{
public override object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture)
{
if (value is not bool boolValue)
return false;
return !boolValue;
}
public override object? ConvertBack(
object? value,
Type targetType,
object? parameter,
CultureInfo culture)
{
if (value is not bool boolValue)
return false;
return !boolValue;
}
}
```
---
## File Structure
```
{Project}/
└── Converters/
├── ConverterMarkupExtension.cs # Base class
├── MultiConverterMarkupExtension.cs # Multi base class
├── BoolToVisibilityConverter.cs
├── NullToVisibilityConverter.cs
└── $0Converter.cs
```
---
## GlobalUsings.cs
Append these to the project's **existing** `GlobalUsings.cs` (do not create a
second one — duplicate `global using` directives fail to compile):
```csharp
global using System;
global using System.Globalization;
global using System.Linq;
global using System.Windows;
global using System.Windows.Data;
global using System.Windows.Markup;
```
---
## Comparison: StaticResource vs MarkupExtension
| Aspect | StaticResource | MarkupExtension |
|--------|---------------|-----------------|
| Resource declaration | Required | Not required |
| XAML usage | `{StaticResource Key}` | `{local:Converter}` |
| Singleton | Manual | Built-in (Lazy) |
| Boilerplate | More | Less |
---
## Related knowledge topics (via WpfDevPackMcp)
Fetch with `WpfDevPackMcp get_wpf_topic`:
- `using-converter-markup-extension` — detailed MarkupExtension pattern (the canonical converter pattern)
- `advanced-data-binding` — MultiBinding patterns
Plugin rule: `.claude/rules/converter-patterns.md` — MarkupExtension singleton, null/UnsetValue handling, TemplateBinding guidance.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.