WPF and Silverlight学习笔记(二十六):基本图形使用(1)2010-12-18 博客园 龙腾于海在WPF中,极大地丰富了关于图形、图像等多媒体元素的操作功能,本节主要 讨论基本的图形。一、基本的图形类型对于WPF中的基本图形类 主要位于System.Windows.Shapes命名空间,其类包括:

需要说明的是,在System.Windows.Media命名空间也存在着类似的类 型:

对应在类名上,添加“Geometry”,这种类称为“几何类 ”,对于几何类只用来描述图形,而不使用任何的画笔(Pen)和刷子 (Brush),即本身没有任何的颜色,并不支持交互,其作用只是用来构建图形 ;另外几何类通常作为Path类的Data属性的值使用(通常通过GeometryGroup构 建复杂图形)。例如:
1: <Window x:Class="WPF_26.Window1"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& quot;
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:media="clr- namespace:System.Windows.Media;assembly=WindowsBase"
5: Title="Window1" Height="300" Width="300">
6: <Grid x:Name="grid">
7: <Grid.RowDefinitions>
8: <RowDefinition />
9: <RowDefinition />
10: </Grid.RowDefinitions>
11: <Rectangle Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center"
12: Width="150" Height="50" Fill="Red" />
13: <Path Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"
14: Fill="Blue">
15: <Path.Data>
16: <RectangleGeometry>
17: <RectangleGeometry.Rect>
18: <Rect Width="150" Height="50" />
19: </RectangleGeometry.Rect>
20: </RectangleGeometry>
21: </Path.Data>
22: </Path>
23: </Grid>
24: </Window>