Silverlight: How to pass True to CommandParameter?

How to pass True to CommandParameter ?

I am currently strongly adding Boolean.True to the resource dictionary, but this seems like a clumsy way to do this.

+4
source share
3 answers

ColinE's answer is fine, but I think I have to lean a bit to determine true / false resources. You need to do this only once:

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

Then you can refer to it as a StaticResource for CommandParameter :

 <Button CommandParameter="{StaticResource BoolTrue}" /> 
+10
source

Because command parameters are of type "object", the XAML parser cannot perform type conversion for you. If you pass "true", the parser will not be able to understand that you want this converted value to be logical. You will need to do this explicitly. You can use the syntax of a property element:

 <Button> <Button.CommandParameter> <sys:Boolean>true</sys:Boolean> </Button.CommandParameter> </Button> 

Where is the sys id displayed:

 xmlns:sys="clr-namespace:System;assembly=mscorlib" 
+11
source

your XAML will change to this.

 <Button Command="{Binding Path=WhateverCommand}" CommandParameter="{x:Static BooleanHelper.True}" /> 
+1
source

Source: https://habr.com/ru/post/1389198/


All Articles