博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows Phone开发(33):路径之其它Geometry 转:http://blog.csdn.net/tcjiaan/article/details/7483835...
阅读量:4499 次
发布时间:2019-06-08

本文共 3256 字,大约阅读时间需要 10 分钟。

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

 

一、LineGeometry

 

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

一起来看看下面的例子。

[html] 
  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轴上的半径。看下面的例子。

[html] 
  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轴方向上的半径长度。看例子。

[html] 
  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个几何图形,如下面例子所示。

[html] 
  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代码。

[html] 
    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>  

转载于:https://www.cnblogs.com/songtzu/archive/2012/07/24/2607116.html

你可能感兴趣的文章
HackerRank "Training the army" - Max Flow
查看>>
jquery next()方法
查看>>
深入剖析js命名空间函数namespace
查看>>
SQLHelper
查看>>
用标准Struts2+mvc写的用户管理
查看>>
Cocos2d-x 3.0 编译出错 解决 error: expected &#39;;&#39; at end of member declaration
查看>>
Ubuntu12.04下载Repo
查看>>
python基础教程_学习笔记10:异常
查看>>
MATLAB——scatter的简单应用
查看>>
linux下复制粘贴快捷键
查看>>
什么是对象
查看>>
记录开发小程序
查看>>
WinSock服务程序
查看>>
巴西柔术第五课:过腿
查看>>
文件的操作
查看>>
网上图书商城项目学习笔记-007登录功能实现
查看>>
关于mysql的级联删除(之前好多人咨询过我)
查看>>
Linux环境下的C/C+基础调试技术2——程序控制
查看>>
wpf动画同步闪烁
查看>>
3.16上午 复习雅思核心词+新单词100个
查看>>