DogXAML - Compound WPF Controls

A tiresome aspect of XAML is that it seems impossible (at least on my current level of understanding) to add snippets as macros - everything in the file has to be provided in full detail at the same level.

If you have many GUI elements which resemble one another this is at best boring, and also means that the "shape" of the XAML is obscured by the detail - although dedicated XML/XAML editors can reduce the aggravation
When you make "compound" controls (for example buttons with both text and image) the problems are magnified (and the specialised editors aren't much help).

So, gradually moving over to the idea of defining XAML in APL code rather than as a file - this takes me further from WYSIWYG, but does let me add complexity to increase simplicity.

Beginning to put this together in a Dyalog namespace script, which may evolve into a series - something along the lines of the APL/W Native GUI controls described elsewhere.

DogButton - Buttons with Images

First simple goal is to define a Button which has both text and an image to suggest to the user what it might be for, looking like this...

What's in the namespace script...

      ∇ z←DogButton(name caption image enabled);⎕IO;⎕ML
    ⍝ DogButton - Button with an image
      ⎕IO ⎕ML←0 3
      z←⊂'<Button Name="',name,'" Width="100" HorizontalAlignment="Left" Margin="5" IsEnabled="',enabled,'">'
      z,←⊂'  <StackPanel Orientation="Horizontal">'
      z,←⊂'     <Image Source="',image,'" Height="16" />'
      z,←⊂'     <Label Content="',caption,'" />'
      z,←⊂'  </StackPanel>'

Which we can use in code defining the entire window (using my usual conventions)...

  z,←#.UTIL.DOGXAML.DogButton'btnCancel' 'Cancel'(#.GLOBALS.homefolder,'Images/cancel.png')'True'

DogSpin - Numeric Spinner

One of the more surprising omissions from WPF is the lack of a spinner (Dyalog's Spinner control), so...

And the code which made (and uses) the window...

 z←TestSpin w;⎕IO;⎕ML;xaml;wdwSpin;spin;callbacks
⍝ Test harness for <DogSpin>
 ⎕IO ⎕ML←0 3
 xaml←⊂'<?xml version="1.0" encoding="utf-8"?>'
 xaml,←⊂' <Window xmlns="" xmlns:x="" '
 xaml,←⊂'     Title="TestSpin" SizeToContent="WidthAndHeight">'
 xaml,←⊂'  <StackPanel>'
 xaml,←#.UTIL.DOGXAML.DogSpin'spnTest' 'How old are you'(50 0 99 1)
 xaml,←#.UTIL.DOGXAML.DogButton'btnOK' 'OK' 'd:/dick/mycode/dyalog132/aplets/dogmap/Images/ok.png' 'True'
 xaml,←⊂'  </StackPanel>'
 wdwSpin←'btnOK' 'spnTest'#.UTIL.WPFTOOLS.SetObjects wdwSpin
 wdwSpin←wdwSpin #.UTIL.WPFTOOLS.SetTags,⊂('Spin' 'spnTest' '#.wdwSpin')
 callbacks←('btnOK' 'Click' '#.TestGet')('spnTest' 'Spin' '')
 wdwSpin←callbacks #.UTIL.WPFTOOLS.SetCallbacks wdwSpin

along with the callback...

 TestGet w;⎕IO;⎕ML
⍝ Get values when OK clicked
 ⎕IO ⎕ML←0 3
 spin←⊃(//⎕VFI wdwSpin.spnTest.Text)

DogSpin - The Namespace Script

  :Section DogSpin
    ∇ z←DogSpin(name label values);⎕IO;⎕ML;value;min;max;step
      ⍝ DogSpin - Spinner like APL/W
      ⎕IO ⎕ML←0 3
      value min max step←values
      z,←⊂'<Label Content="',label,'" />'
      z,←⊂'<StackPanel Height="20" Orientation="Horizontal">'
      z,←⊂'<TextBox Width="80" Name="',name,'" Text="',(⍕value),'" Tag="',(⍕min max step),'"/>'
      z,←⊂'<StackPanel Width="20" Orientation="Vertical">'
      z,←⊂'<Button Name="',(name,'Up'),'" Height="10" Content="∆"/>'
      z,←⊂'<Button Name="',(name,'Dn'),'" Height="10" Content="∇"/>'
    ∇ z←DogSpinUp w;⎕IO;⎕ML;spin;min;max;step;value;wdwName
    ⍝ Callback for Up button
      ⎕IO ⎕ML←0 3
      min max step←⊃(//⎕VFI⍎'#.wdwSpin.',(¯2↓(↑w).Name),'.Tag')
    ∇ z←DogSpinDn w;⎕IO;⎕ML;spin;min;max;step;value;wdwName
    ⍝ Callback for Down button
      ⎕IO ⎕ML←0 3
      min max step←⊃(//⎕VFI⍎wdwName,'.',(¯2↓(↑w).Name),'.Tag')


More to come (probably)....


Page updated 26 July 2013; Copyright © Dick Bowman 2013