wpf 绘制图形
时间: 2023-10-06 11:10:07 浏览: 113
在WPF中,可以使用XAML或代码来绘制图形。以下是一些示例:
1. 使用XAML绘制矩形:
```xaml
<Rectangle Width="100" Height="100" Fill="Blue" />
```
2. 使用代码绘制矩形:
```csharp
Rectangle rect = new Rectangle();
rect.Width = 100;
rect.Height = 100;
rect.Fill = Brushes.Blue;
```
3. 使用XAML绘制圆形:
```xaml
<Ellipse Width="100" Height="100" Fill="Red" />
```
4. 使用代码绘制圆形:
```csharp
Ellipse ellipse = new Ellipse();
ellipse.Width = 100;
ellipse.Height = 100;
ellipse.Fill = Brushes.Red;
```
5. 使用XAML绘制线条:
```xaml
<Line X1="0" Y1="0" X2="100" Y2="100" Stroke="Black" StrokeThickness="2" />
```
6. 使用代码绘制线条:
```csharp
Line line = new Line();
line.X1 = 0;
line.Y1 = 0;
line.X2 = 100;
line.Y2 = 100;
line.Stroke = Brushes.Black;
line.StrokeThickness = 2;
```
阅读全文