Custom Converter While Using 2015⌶

Using (or providing) Microsoft.NET Classes
Post Reply
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Custom Converter While Using 2015⌶

Post by PGilbert »

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
User avatar
JohnD|Dyalog
Posts: 74
Joined: Wed Oct 01, 2008 9:35 am

Re: Custom Converter While Using 2015⌶

Post by JohnD|Dyalog »

Hello Pierre,

This is something that we definately want to add to the 2015⌶ support, but it can't be done at the moment.

There's also a need for functions for validation, and setters and getters of values and so on, and we want to provide a consistent interface to these functions.

These requests for extensions are exactly the feedback we want for the data binding in 14.0 so please keep the suggestions coming.

Best Regards,
John Daintree.
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Custom Converter While Using 2015⌶

Post by PGilbert »

Hello John, looks like if you declared the bind as Int32 for the property IsChecked of a WPF CheckBox or RadioButton you will be able to Set/Get the property with 0 and 1 in Apl ! I have tried it with nothing and Boolean and it did not worked.

For the Visibility property if you declare the bind as String you will be able to Set/Get the property with the words 'Visible', 'Hidden' and 'Collapsed'. With the help of a Dfn function you can convert those words to numbers of your choice. I have tried to make it work directly with numbers but was not successfull. One could use also a converter in the Xaml like the one of Microsoft called BooleanToVisibilityConverter Class and that way the bind could use numbers (0 or 1) to define the visibility to 'Visible' and 'Collapsed' but I have not tried it. Syncfusion also has many converters to be used with Xaml.

An idea would be to have a third column in the options of the bind to set the name of a dfn function to act as a converter.

Regards
Post Reply