Windows Phone开发(33):路径之其它Geometry

移动开发
Windows Phone具有桌面定制、图标拖拽、滑动控制等一系列前卫的操作体验。其主屏幕通过提供类似仪表盘的体验来显示新的电子邮件、短信、未接来电、日历约会等,让人们对重要信息保持时刻更新。

上一节中,我们把最复杂的PathGeometry给干了,生剩下几个家伙就好办事了。一起来见见他们的真面目吧。

一、LineGeometry

这个几何图形就很简单了,一条线段,两个点——StartPoint And EndPoint。

一起来看看下面的例子。

  1. <Path Grid.Column="0" Grid.Row="0">   
  2.     <Path.Data>   
  3.         <LineGeometry StartPoint="20,5" EndPoint="200,320"/>   
  4.     </Path.Data>   
  5. </Path>   

运行之后你会看到以下情景:

二、RectangleGeometry

它呈现一人矩形的几何图形,Rect指示其中矩形的位置大小,在XAML中可以用4个数值表示,即X、Y、Width、Height;别外,RadiusX和RadiusY表示圆角在X轴和Y轴上的半径。看下面的例子。

  1. <Path Grid.Column="1" Grid.Row="0">   
  2.     <Path.Data>   
  3.         <RectangleGeometry Rect="12,6,125,90" RadiusX="24" RadiusY="30"/>   
  4.     </Path.Data>   
  5. </Path>   

运行效果如下图所示。

三、EllipseGeometry

表示一个椭圆的几何图形,Center属性为椭圆的中心点的坐标,RadiusX和RadiusY分别为X轴方向上和Y轴方向上的半径长度。看例子。

  1. <Path Grid.Column="0" Grid.Row="1">   
  2.     <Path.Data>   
  3.         <EllipseGeometry Center="100,180" RadiusX="55" RadiusY="120"/>   
  4.     </Path.Data>   
  5. </Path> 

运行效果如下:

四、GeometryGroup

严格上说,它不属性一种几何图形,但它很有用,因为它可以同时包含N个几何图形,如下面例子所示。

  1. <Path Grid.Column="1" Grid.Row="1">   
  2.     <Path.Data>   
  3.         <GeometryGroup>   
  4.             <LineGeometry StartPoint="32,185" EndPoint="180,230"/>   
  5.             <RectangleGeometry Rect="35,85,136,96" RadiusX="25" RadiusY="5"/>   
  6.             <EllipseGeometry Center="112,130" RadiusX="45" RadiusY="36"/>   
  7.         </GeometryGroup>   
  8.     </Path.Data>   
  9. </Path>   

运行效是如下所示:

下面是本节示例的完整XAML代码。

  1. <phone:PhoneApplicationPage    
  2.     x:Class="Sample.MainPage"   
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"   
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"   
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"   
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}"   
  11.     FontSize="{StaticResource PhoneFontSizeNormal}"   
  12.     Foreground="{StaticResource PhoneForegroundBrush}"   
  13.     SupportedOrientations="Portrait" Orientation="Portrait"   
  14.     shell:SystemTray.IsVisible="True">   
  15.    
  16.     <phone:PhoneApplicationPage.Resources>   
  17.         <Style TargetType="Path">   
  18.             <Setter Property="HorizontalAlignment" Value="Stretch"/>   
  19.             <Setter Property="VerticalAlignment" Value="Stretch"/>   
  20.             <Setter Property="Margin" Value="20"/>   
  21.             <Setter Property="Stroke" Value="Blue"/>   
  22.             <Setter Property="StrokeThickness" Value="8"/>   
  23.         </Style>   
  24.     </phone:PhoneApplicationPage.Resources>   
  25.        
  26.     <Grid>   
  27.         <Grid.ColumnDefinitions>   
  28.             <ColumnDefinition Width="*"/>   
  29.             <ColumnDefinition Width="*"/>   
  30.         </Grid.ColumnDefinitions>   
  31.         <Grid.RowDefinitions>   
  32.             <RowDefinition Height="*"/>   
  33.             <RowDefinition Height="*"/>   
  34.         </Grid.RowDefinitions>   
  35.         <Path Grid.Column="0" Grid.Row="0">   
  36.             <Path.Data>   
  37.                 <LineGeometry StartPoint="20,5" EndPoint="200,320"/>   
  38.             </Path.Data>   
  39.         </Path>   
  40.         <Path Grid.Column="1" Grid.Row="0">   
  41.             <Path.Data>   
  42.                 <RectangleGeometry Rect="12,6,125,90" RadiusX="24" RadiusY="30"/>   
  43.             </Path.Data>   
  44.         </Path>   
  45.         <Path Grid.Column="0" Grid.Row="1">   
  46.             <Path.Data>   
  47.                 <EllipseGeometry Center="100,180" RadiusX="55" RadiusY="120"/>   
  48.             </Path.Data>   
  49.         </Path>   
  50.         <Path Grid.Column="1" Grid.Row="1">   
  51.             <Path.Data>   
  52.                 <GeometryGroup>   
  53.                     <LineGeometry StartPoint="32,185" EndPoint="180,230"/>   
  54.                     <RectangleGeometry Rect="35,85,136,96" RadiusX="25" RadiusY="5"/>   
  55.                     <EllipseGeometry Center="112,130" RadiusX="45" RadiusY="36"/>   
  56.                 </GeometryGroup>   
  57.             </Path.Data>   
  58.         </Path>   
  59.     </Grid>   
  60. </phone:PhoneApplicationPage>   

 

责任编辑:闫佳明 来源: oschina
相关推荐

2013-04-19 17:11:02

Windows PhoWindows Pho

2013-04-23 16:59:22

Windows Pho路径标记语法

2013-07-31 13:13:50

Windows PhoMVVM模式

2013-04-24 13:19:06

Windows Pho动画DoubleAni

2013-04-24 13:31:59

Windows Pho动画之ColorAni

2013-04-24 13:43:10

Windows Pho动画PointAnim

2013-07-31 13:36:07

Windows PhoVS调试技巧Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概论

2013-07-30 11:18:37

Windows PhoWindows Pho

2010-08-06 15:44:28

Windows PhoWindows PhoSilverlight

2010-04-08 17:40:23

Windows Pho

2013-04-17 14:47:19

Windows PhoWindows Pho

2011-06-07 11:35:38

Windows Pho

2010-07-16 15:29:02

Windows Pho

2012-08-16 10:35:50

Windows Pho
点赞
收藏

51CTO技术栈公众号