Boolean CommandParameter in XAML Boolean CommandParameter in XAML wpf wpf

Boolean CommandParameter in XAML


This might be a bit of a hack but you can derive from the KeyBinding class:

public class BoolKeyBinding : KeyBinding{    public bool Parameter    {        get { return (bool)CommandParameter; }        set { CommandParameter = value; }    }}

Usage:

<local:BoolKeyBinding ... Parameter="True"/>

And another not so weird solution:

xmlns:s="clr-namespace:System;assembly=mscorlib"
<Application.Resources>    <!-- ... -->    <s:Boolean x:Key="True">True</s:Boolean>    <s:Boolean x:Key="False">False</s:Boolean></Application.Resources>

Usage:

<KeyBinding ... CommandParameter="{StaticResource True}"/>


The easiest is to define the following in the Resources

<System:Boolean x:Key="FalseValue">False</System:Boolean><System:Boolean x:Key="TrueValue">True</System:Boolean>

and use it like:

<Button CommandParameter="{StaticResource FalseValue}"/>


Or, maybe that:

<Button.CommandParameter>    <s:Boolean>True</s:Boolean></Button.CommandParameter>

Where s is the namespace:

 xmlns:s="clr-namespace:System;assembly=mscorlib"