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

上一节中,我们把最复杂的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>  


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值