1

我在msdn中找到了一个在.XAML文件中绘制形状的链接,但是如何用c#做同样的事情,在silverlight的wp7中用c#绘制一个形状而不使用xna?

4

1 回答 1

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);
于 2012-04-10T11:30:54.697 回答