Reputation: 13
i found a link in msdn to draw a shape in .XAML file, but how to do the same with c#, drawing a shape with c# in wp7 in silverlight without use xna?
Upvotes: 1
Views: 1670
Reputation: 13250
I think this http://www.windowsphonegeek.com/tips/drawing-in-wp7-1-getting-started-and-line-shape will help you to draw shapes using C#.
Your XAML:
<Canvas x:Name="ContentPanelCanvas" Grid.Row="1" Background="Transparent" Margin="12,0,12,0">
<Line X1="10" Y1="100" X2="150" Y2="100" Stroke="Green" StrokeThickness="5"/>
</Canvas>
C#:
Line line = new Line();
line.Stroke = new SolidColorBrush(Colors.Purple);
line.StrokeThickness = 15;
Point point1 = new Point();
point1.X = 10.0;
point1.Y = 100.0;
Point point2 = new Point();
point2.X = 150.0;
point2.Y = 100.0;
line.X1 = point1.X;
line.Y1 = point1.Y;
line.X2 = point2.X;
line.Y2 = point2.Y;
this.ContentPanelCanvas.Children.Add(line);
Upvotes: 2