tags:

views:

116

answers:

1

I want to replace

<Button Text="Foo" Command="{Binding Foo}">
    <Button.CommandParameter>
        <System:Boolean>True</System:Boolean>
    </Button.CommandParameter>
</Button>

with something like

<Button ... CommandParameter="{???}"/>
+3  A: 

You can write a markup extension by deriving from the MarkupExtension class and implementing the ProvideValue method:

public class BooleanValueExtension : MarkupExtension
{
  private readonly bool _value;

  public BooleanValueExtension(bool value)
  {
    _value = value;
  }

  public override object ProvideValue(IServiceProvider serviceProvider)
  {
    return _value;
  }
}

You can then use this using the brace syntax:

<Button CommandParameter="{local:BooleanValue True}" />
itowlson