XAML

Code




WPF Tutorial Contents

APL  Home Page



XAML


<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Canvas>
<Path Stroke="Black" StrokeThickness="1" >
  <Path.Data>
    <LineGeometry StartPoint="10,20" EndPoint="100,130" />
  </Path.Data>
</Path>
<Path Fill="Gold" Stroke="Black" StrokeThickness="1" >
  <Path.Data>
    <EllipseGeometry Center="50,250" RadiusX="50" RadiusY="50" />
  </Path.Data>
</Path>
<Path Fill="LemonChiffon" Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <RectangleGeometry Rect="250,50,25,25" />
  </Path.Data>
</Path>
<Path Stroke="Blue" StrokeThickness="1" >
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>       
        <PathFigure StartPoint="250,200">
          <PathFigure.Segments>
            <PolyLineSegment Points="250,250 300,200 400,250" />
          </PathFigure.Segments>
        </PathFigure>               
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>
<Path Stroke="Red" Fill="Green" StrokeThickness="1" >
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>       
        <PathFigure StartPoint="450,200">
          <PathFigure.Segments>
            <PolyLineSegment Points="650,200 650,300 500,275" />
          </PathFigure.Segments>
        </PathFigure>               
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>
</Canvas>
</Window>

Code


This isn't directly equivalent, but my head hurts after struggling against the apparent arbitrariness of  the .NET class structure and trying to figure out how to position stuff that I'm drawing.  Anyhow, the essence so far is sorting out what goes into ⎕USING and the calling.  There's redundancy here - hopefully it will simplify and become more logical as time passes...

XAML for a Drawing Space


<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Canvas Name="cvsDraw" Height="500" Width="500">
</Canvas>
</Window>


A Simple Drawing Function


draw w;⎕IO;⎕ML;form;xaml
⍝ Simple 2d graphics
 ⎕IO ⎕ML←0 3
 xaml←#.UTIL.FILE.ReadUnicodeFile w
 form←#.UTIL.WPF.LoadXaml xaml''
 form.cvsDraw←form.FindName⊂'cvsDraw'
 form←AddLine form
 form←AddEllipse form
 form←AddRectangle form
 form←AddPolyline form
 form←AddPolygon form
 {}form.ShowDialog


Draw a Single Line


 z←AddLine w;⎕IO;⎕ML;⎕USING;line
⍝ Add a line to the form
 ⎕IO ⎕ML←0 3
 z←w
 ⎕USING←,⊂'System,System.dll'
 ⎕USING,←⊂'System.Windows.Shapes,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationFramework.dll'
 ⎕USING,←⊂'System.Windows.Media,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationCore.dll'
 line←z.⎕NEW Line
 line.(X1 Y1 X2 Y2)←20 50 100 100
 line.StrokeThickness←2
 line.Stroke←Brushes.Black
 z.cvsDraw.SetLeft(line ¯250)
 z.cvsDraw.SetTop(line ¯100)
 {}z.cvsDraw.Children.Add line


Draw an Ellipse


 z←AddEllipse w;⎕IO;⎕ML;⎕USING;ellipse
⍝ Add an ellipse to the form
 ⎕IO ⎕ML←0 3
 z←w
 ⎕USING←,⊂'System,System.dll'
 ⎕USING,←⊂'System.Windows.Shapes,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationFramework.dll'
 ⎕USING,←⊂'System.Windows.Media,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationCore.dll'
 ellipse←z.⎕NEW Ellipse
 ellipse.Width←200
 ellipse.Height←100
 ellipse.StrokeThickness←1
 ellipse.Stroke←Brushes.Blue
 ellipse.Fill←Brushes.Yellow
 z.cvsDraw.SetLeft(ellipse 200)
 z.cvsDraw.SetTop(ellipse 100)
 {}z.cvsDraw.Children.Add ellipse


You'd think - if this nonsense had been designed by a rational being that Centre (or even Center) would be an Ellipse property.  But it isn't, and things keep on getting worse...

Draw a Rectangle


 z←AddRectangle w;⎕IO;⎕ML;⎕USING;rect
⍝ Add an rectangle to the form
 ⎕IO ⎕ML←0 3
 z←w
 ⎕USING←,⊂'System,System.dll'
 ⎕USING,←⊂'System.Windows.Shapes,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationFramework.dll'
 ⎕USING,←⊂'System.Windows.Media,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationCore.dll'
 rect←z.⎕NEW Rectangle
 rect.Width←50
 rect.Height←50
 rect.StrokeThickness←1
 rect.Stroke←Brushes.Red
 rect.Fill←Brushes.Green
 z.cvsDraw.SetLeft(rect ¯50)
 z.cvsDraw.SetTop(rect 200)
 {}z.cvsDraw.Children.Add rect


Draw a Polyline


 z←AddPolyline w;⎕IO;⎕ML;⎕USING;polyline;point;pc
⍝ Add an polyline to the form
 ⎕IO ⎕ML←0 3
 z←w
 ⎕USING←,⊂'System,System.dll'
 ⎕USING,←⊂'System.Windows,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\WindowsBase.dll'
 ⎕USING,←⊂'System.Windows.Shapes,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationFramework.dll'
 ⎕USING,←⊂'System.Windows.Media,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationCore.dll'
 polyline←z.⎕NEW Polyline
 pc←⎕NEW PointCollection
 :For point :In (1 50)(10 80)(20 40)
     pc.Add ⎕NEW Point(↑83 645 ⎕DR point)
 :EndFor
 polyline.Points←pc
 polyline.StrokeThickness←1
 polyline.Stroke←Brushes.Red
 z.cvsDraw.SetLeft(polyline 0)
 z.cvsDraw.SetTop(polyline 0)
 {}z.cvsDraw.Children.Add polyline


Draw a Polygon


 z←AddPolygon w;⎕IO;⎕ML;⎕USING;polygon;point;pc
⍝ Add an polygon to the form
 ⎕IO ⎕ML←0 3
 z←w
 ⎕USING←,⊂'System,System.dll'
 ⎕USING,←⊂'System.Windows,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\WindowsBase.dll'
 ⎕USING,←⊂'System.Windows.Shapes,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationFramework.dll'
 ⎕USING,←⊂'System.Windows.Media,c:\windows\microsoft.net\framework64\v4.0.30319\wpf\PresentationCore.dll'
 polygon←z.⎕NEW Polygon
 pc←⎕NEW PointCollection
 :For point :In (1 50)(10 80)(50 50)
     pc.Add ⎕NEW Point(↑83 645 ⎕DR point)
 :EndFor
 polygon.Points←pc
 polygon.StrokeThickness←2
 polygon.Stroke←Brushes.Red
 polygon.Fill←Brushes.LightSeaGreen
 z.cvsDraw.SetLeft(polygon 100)
 z.cvsDraw.SetTop(polygon 100)
 {}z.cvsDraw.Children.Add polygon