VBE as a Visual Design Tool

Dyalog's WPF Workspace

All the Code You Need

WPF Tutorial Contents

APL  Home Page

VBE as a Visual Design Tool

Easiest way to design forms is visually, so (if you haven't already) download Visual Basic Express from Microsoft and install it.

Start VBE and choose "New Project" then "WPF Application".

Put a Button and a TextBox into the Window, it'll look something like this (we're not aiming to win any design awards)...

Edit the Button properties so that it has Content "Press Me" (as above) and Name "btnPress".

Edit the TextBox properties so that it has Name "txtThanks".

Save the file (not the project, just the xaml file - we don't care about the project, that's for VB programmers).

Edit the file with your preferred text editor to remove the x:Class="MainWindow" that's in the first line, save it again.

You now have a xaml file which looks someting like this (allowing for line-breaks)...

    Title="MainWindow" Height="350" Width="525">
        <Button Content="Press Me" Height="23" HorizontalAlignment="Left" Margin="124,58,0,0"       Name="btnPress" VerticalAlignment="Top" Width="75" />
        <TextBox Height="85" HorizontalAlignment="Left" Margin="124,120,0,0" Name="txtThanks" VerticalAlignment="Top" Width="198" />

Dyalog's WPF Workspace

Get a copy of the WPF workspace written by Jonathan Manktelow and distributed at the Dyalog'08 conference (you may have to as Dyalog for it individually, they don't seem to have included it in the interpreter package and I can't find a likely source on the Dyalog website).

All the Code You Need

Now that you have the xaml file and the WPF workspace, there's a little APL to write...

     ∇ foo w;⎕IO;⎕ML;f
[1]   ⍝ Simple WPF demonstrator
[2]    ⎕IO ⎕ML←0 3
[3]    f←#.WPF.LoadXamlFile w
[4]    f.btn←f.FindName⊂'btnPress'
[5]    f.txt←f.FindName⊂'txtThanks'
[6]    f.btn.onClick←'Thanks'
[7]    {}f.ShowDialog

  ∇ Thanks w;⎕IO;⎕ML           
[1]   ⍝ onClick callback for btnPress        
[2]    ⎕IO ⎕ML←0 3         
[3]    f.txt.Text←'Thanks'          

And bingo...

foo 'filenamegoeshere'

What could possibly go wrong?

Well, you may see a screenful of abuse in the Status Window about the file being in an invalid format - I get this from time to time when a xaml file transfers out of VBE and is used by APL, it seems to be down to Unicode - if it happens just use your text editor to juggle the file encoding and retry (don't forget to clear the stack).

And aside from that, there you go.  Things are a bit untidy with globals, but you'll soon find what works for you.  Everything further is refinement...