Search code examples
silverlightcommandcommandparameter

Silverlight: How do I pass True to a CommandParameter?


How do I pass True to a CommandParameter?

Currently I am imperatively adding Boolean.True to the resource dictionary, but that seems like a clumsy way to do it.


Solution

  • ColinE's answer is fine, but I think it's a bit neater to define the true/false as resources. You only have to do that once:

    <UserControl.Resources>
        <sys:Boolean x:Key="BoolTrue">True</sys:Boolean>
        <sys:Boolean x:Key="BoolFalse">False</sys:Boolean>
    </UserControl.Resources>
    

    Then you can reference it as a StaticResource for the CommandParameter:

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