Custom Converter While Using 2015⌶
Posted: Sun Jul 06, 2014 1:37 pm
If you bind an Apl variable to the 'IsChecked' property of a .Net CheckBox the returned value following user interaction will be 0 or 1. However in order for the Apl variable to set correctly that property in the GUI it needs to be set to 'True' for 1 and 'False' for 0 otherwise the binding will not work.
Will it be possible to use a 'Custom Converter' to do that work while binding using 2015⌶ ? I have tried the following converter but it is not working:
⍝ Boolean Converter
BoolCvt←{
{
⍵≡1:'True' ⍝ 1 = 'True'
⍵≡0:'False' ⍝ 0 = 'False'
⍵≡'True':1 ⍝ 'True' = 1
⍵≡'False':0 ⍝ 'False' = 0
' '=↑1↑0⍴⍵:0 ⍝ Any character = 0
'False'}¨⍵ ⍝ Any number = 'False'
}
in an expression like:
ed1_IsChecked←1
Win.ed1.IsChecked←BoolCvt (2015⌶)'ed1_IsChecked'
The same question apply also when you need to have a 'Visibility' Converter of this type:
⍝ Visibility Converter
VisiCvt←{
{
⍵≡1:'Visible' ⍝ 1 = 'Visible'
⍵≡0:'Hidden' ⍝ 0 = 'Hidden'
⍵≡¯1:'Collapsed' ⍝ ¯1 = 'Collapsed'
⍵≡'Visible':1 ⍝ 'Visible' = 1
⍵≡'Hidden':0 ⍝ 'Hidden' = 0
⍵≡'Collapsed':¯1 ⍝ 'Collapsed' = ¯1
' '=↑1↑0⍴⍵:1 ⍝ Any character = 1
'Visible'}¨⍵ ⍝ Any number = 'Visible'
}
You need to convert 1, 0 and -1 to 'Visible', 'Hidden' and 'Collapsed'.
Thanks in advance,
Pierre Gilbert
Will it be possible to use a 'Custom Converter' to do that work while binding using 2015⌶ ? I have tried the following converter but it is not working:
⍝ Boolean Converter
BoolCvt←{
{
⍵≡1:'True' ⍝ 1 = 'True'
⍵≡0:'False' ⍝ 0 = 'False'
⍵≡'True':1 ⍝ 'True' = 1
⍵≡'False':0 ⍝ 'False' = 0
' '=↑1↑0⍴⍵:0 ⍝ Any character = 0
'False'}¨⍵ ⍝ Any number = 'False'
}
in an expression like:
ed1_IsChecked←1
Win.ed1.IsChecked←BoolCvt (2015⌶)'ed1_IsChecked'
The same question apply also when you need to have a 'Visibility' Converter of this type:
⍝ Visibility Converter
VisiCvt←{
{
⍵≡1:'Visible' ⍝ 1 = 'Visible'
⍵≡0:'Hidden' ⍝ 0 = 'Hidden'
⍵≡¯1:'Collapsed' ⍝ ¯1 = 'Collapsed'
⍵≡'Visible':1 ⍝ 'Visible' = 1
⍵≡'Hidden':0 ⍝ 'Hidden' = 0
⍵≡'Collapsed':¯1 ⍝ 'Collapsed' = ¯1
' '=↑1↑0⍴⍵:1 ⍝ Any character = 1
'Visible'}¨⍵ ⍝ Any number = 'Visible'
}
You need to convert 1, 0 and -1 to 'Visible', 'Hidden' and 'Collapsed'.
Thanks in advance,
Pierre Gilbert