From wpf-dev-pack
Resolves WPF CommandParameter enum type mismatch errors using x:Static markup extension to pass actual enum values instead of strings in MVVM commands.
npx claudepluginhub christian289/dotnet-with-claudecode --plugin wpf-dev-packThis skill uses the workspace's default tool permissions.
> **MVVM Framework Rule**: `.claude/rules/dotnet/wpf/mvvm-framework.md` 설정에 따라 코드 스타일이 결정됩니다.
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
MVVM Framework Rule:
.claude/rules/dotnet/wpf/mvvm-framework.md설정에 따라 코드 스타일이 결정됩니다. Prism 9 사용 시 → PRISM.md 참조
When binding enum values to CommandParameter in WPF, passing as string causes type mismatch error.
System.ArgumentException: 'Parameter "parameter" (object) cannot be of type System.String,
as the command type requires an argument of type MyNamespace.MyEnum.'
When specifying CommandParameter="Pan" as a string in XAML, WPF passes it as System.String type. However, if the Command expects a specific enum type, automatic type conversion does not occur.
x:Static to Directly Reference Enum Value<!-- Namespace declaration -->
xmlns:viewmodels="clr-namespace:MyApp.ViewModels;assembly=MyApp.ViewModels"
<!-- Wrong method (passed as String) -->
<Button Command="{Binding SelectToolCommand}"
CommandParameter="Pan" />
<!-- Correct method (passed as Enum type) -->
<Button Command="{Binding SelectToolCommand}"
CommandParameter="{x:Static viewmodels:ViewerTool.Pan}" />
public enum ViewerTool
{
None,
Pan,
Zoom,
WindowLevel
}
public partial class ViewerViewModel : ObservableObject
{
[ObservableProperty] private ViewerTool _currentTool = ViewerTool.Pan;
[RelayCommand]
private void SelectTool(ViewerTool tool)
{
CurrentTool = tool;
}
}
<UserControl xmlns:viewmodels="clr-namespace:MyApp.ViewModels;assembly=MyApp.ViewModels">
<StackPanel Orientation="Horizontal">
<!-- Select Pan tool -->
<ToggleButton Content="Pan"
Command="{Binding SelectToolCommand}"
CommandParameter="{x:Static viewmodels:ViewerTool.Pan}"
IsChecked="{Binding CurrentTool,
Converter={StaticResource EnumToBoolConverter},
ConverterParameter={x:Static viewmodels:ViewerTool.Pan}}" />
<!-- Select Zoom tool -->
<ToggleButton Content="Zoom"
Command="{Binding SelectToolCommand}"
CommandParameter="{x:Static viewmodels:ViewerTool.Zoom}"
IsChecked="{Binding CurrentTool,
Converter={StaticResource EnumToBoolConverter},
ConverterParameter={x:Static viewmodels:ViewerTool.Zoom}}" />
<!-- Select Window/Level tool -->
<ToggleButton Content="W/L"
Command="{Binding SelectToolCommand}"
CommandParameter="{x:Static viewmodels:ViewerTool.WindowLevel}"
IsChecked="{Binding CurrentTool,
Converter={StaticResource EnumToBoolConverter},
ConverterParameter={x:Static viewmodels:ViewerTool.WindowLevel}}" />
</StackPanel>
</UserControl>
assembly= when using enum from different projectx:Static for ConverterParameter as wellpublic class EnumToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(parameter) ?? false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? parameter : Binding.DoNothing;
}
}