Here's another approach where you define your own markup extensions that return True
or False
(or any other value you wish). Then you simply use them right in XAML like any other markup extension:
public class TrueExtension : MarkupExtension {
public override object ProvideValue(IServiceProvider serviceProvider) => true;
}
public class FalseExtension : MarkupExtension {
public override object ProvideValue(IServiceProvider serviceProvider) => false;
}
public class DoubleExtension : MarkupExtension {
public DoubleExtension(){};
public DoubleExtension(double value) => Value = value;
public double Value { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider) => Value;
}
You then use them like this (assuming your imported namespace is mx
):
<KeyBinding Key="Enter"
Command="{Binding ReturnResultCommand}"
CommandParameter="{mx:True}" />
<Button Visibility="{Binding SomeProperty,
Converter={SomeBoolConverter},
ConverterParameter={mx:True}}">
<!-- This guarantees the value passed is a double equal to 42.5 -->
<Button Visibility="{Binding SomeProperty,
Converter={SomeDoubleConverter},
ConverterParameter={mx:Double 42.5}}">
I actually define lots of custom MarkupExtension
classes for a lot of common things that I don't want to necessarily store in my resources.