• Windows Phone开发(33):路径之其它Geometry 转:http://blog.csdn.net/tcjiaan/article/details/7483835


    上一节中,我们把最复杂的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>  
  • 相关阅读:
    二维数组的查找问题
    将字符串编码成数值,求数值最大和问题(今日头条笔试题)
    链表的倒序打印
    求方程的近似解
    多边形构成问题(今日头条笔试题)
    各种语言数据类型大小
    luoguP1551 亲戚
    Codeforces 764 A-B
    Mixing Chemicals
    Day 8 of JZJX
  • 原文地址:https://www.cnblogs.com/songtzu/p/2607116.html
Copyright © 2020-2023  润新知