我在msdn中找到一个链接来在.XAML文件中绘制一个形状,但是如何用c#做同样的事情,在没有使用xna的情况下在silverlight中用wp7绘制c#形状?
答案 0 :(得分:2)
我认为这个http://www.windowsphonegeek.com/tips/drawing-in-wp7-1-getting-started-and-line-shape将帮助您使用C#绘制形状。
您的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);