Pages

Monday 10 May 2010

Canvas

I think this is about the minimum you need to draw a shape on a Canvas programmatically.
<Window x:Class="DrawStateMachineMap.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<Grid>
<Canvas Name="MainCanvas"></Canvas>
</Grid>
</Window>

      public Window2()
{
InitializeComponent();

Rectangle aRectangle = new Rectangle();
aRectangle.Width = 100;
aRectangle.Height = 50;
aRectangle.Stroke = Brushes.Red;

Canvas.SetLeft(aRectangle, 10);
Canvas.SetTop(aRectangle, 15);

MainCanvas.Children.Add(aRectangle);
}

No comments: