IntegerTextBox


Display a Window containing both a WPF-vanilla TextBox and a SyncFusion IntegerTextBox, prefilling values and retrieving (new) values when the user closes the Window.

This example a little more complex than most to draw out parallels/differences between the two controls and also binding versus direct access to set and get values.



XAML


∇  xaml←IntegerTextBoxXAML opt
⍝ XAML for the IntegerTextBox example
 xaml←⊂'<Window'
 xaml,←⊂'    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"'
 xaml,←⊂'    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"'
 xaml,←⊂'    xmlns:sftools="clr-namespace:Syncfusion.Windows.Shared;assembly=SyncFusion.Shared.WPF"'
 xaml,←⊂'    SizeToContent="WidthandHeight" >'
 xaml,←⊂'    <StackPanel>'
 :Select opt
 :Case 'Binding'
     xaml,←⊂'        <sftools:IntegerTextBox Name="itbox" Value="{Binding intSource,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>'
     xaml,←⊂'        <TextBox                Name="txt"   Text="{Binding txtSource,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>'
 :Case 'Direct'
     xaml,←⊂'        <sftools:IntegerTextBox Name="itbox"/>'
     xaml,←⊂'        <TextBox Name="txt"/>'
 :EndSelect
 xaml,←⊂'    </StackPanel>'
 xaml,←⊂'</Window>'


Code


∇   z←opt IntegerTextBox(int txt);⎕IO;⎕ML;xaml;⎕USING;wvalue;intSource;txtSource
⍝ Simple IntegerTextBox example
 ⎕IO ⎕ML←0 3
 ⎕USING←,⊂'System'
 xaml←IntegerTextBoxXAML opt
 #.window←#.UTIL.WPF.LoadXaml xaml(⊂'SyncTools')
 window_itbox window_txtBox←{#.window.FindName⊂⍵}¨'itbox' 'txt'
 :Select opt
 :Case 'Binding'
     ⎕EX'intSource'
     intSource←int
     window_itbox.DataContext←Int32(2015⌶)'intSource'
     ⎕EX'txtSource'
     txtSource←txt
     window_txtBox.DataContext←2015⌶'txtSource'
 :Case 'Direct'
     window_itbox.Value←Convert.ToInt64 int
     window_txtBox.Text←txt
 :EndSelect
 {}#.window.ShowDialog
 :Select opt
 :Case 'Binding'
     z←intSource txtSource
 :Case 'Direct'
     z←(Convert.ToInt32 window_itbox.Value)window_txtBox.Text
 :EndSelect


The 'SyncTools' argument to #.UTIL.LoadXAML has the effect of adding

'Syncfusion.Windows.Shared,Syncfusion/4.5/Syncfusion.Shared.WPF.dll'
'SyncFusion.Windows.Tools.Controls,Syncfusion/4.5/Syncfusion.Tools.WPF.dll

 to the ⎕USING list of
LoadXAML

Note the trade-off in code complexity - using Binding has a more involved setup (both in the XAML and the code), but a much simpler value retrieval at the end.

Thanks to Vince at Dyalog for pointing me in the direction of ConvertToInt64 and ConvertToInt32.

Something else to wonder about is why we have to go through all this System.Convert stuff when the rather similar PercentTextBox doesn't require any such hocuspocus.

Operation


      'Binding' #.IntegerTextBox.IntegerTextBox 666   'the devil'    
667  the devil plus one

Unresolved Issues


Exploring various properties.