WP7 开发(六) WP7控件开发(三)-绘图控件 地图控件

   -InkPresenter:产生手写效果

    示例代码:

        Stroke newStroke;

        private void inkPresenter1_LostMouseCapture(object sender, MouseEventArgs e)

        {

            newStroke = null;//失去焦点时销毁上一次的Stroke

        }

 

        private void inkPresenter1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

        {

            inkPresenter1.CaptureMouse();//开始捕获鼠标移动路径

            StylusPointCollection spc = new StylusPointCollection();

            spc.Add(e.StylusDevice.GetStylusPoints(inkPresenter1));

            newStroke = new Stroke();

            this.inkPresenter1.Strokes.Add(newStroke);

        }

 

        private void inkPresenter1_MouseMove(object sender, MouseEventArgs e)

        {

            if (newStroke != null)

            {

                //记录鼠标在inkPresenter1上的移动的点

                newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkPresenter1));

            }

        }

   -Path:通过Markup Syntax来绘制一系列的线条,通过Geometries来绘制形状

    示例:

     <Path Height="428" HorizontalAlignment="Left"

     Margin="12,127,0,0" Name="path1" Stroke="Red" StrokeThickness="10" VerticalAlignment="Top"       Width="456" Fill="Green">

      <Path.Data>

          <EllipseGeometry Center="200,200"  RadiusX="100" RadiusY="30"/>

      </Path.Data>

    </Path>

   -Ellipse:绘制圆形或椭圆形

   -Rectangle:绘制矩形

   -Line:绘制两点间的连线

   -Polygon:绘制封闭多边形

   -Polyline:绘制封闭、开发多边形

   -Glyphs:绘制字母、符号、字符等,主要用来显示Unicode字符,需要加载字体库从网上下载字体库,对于  使用不多的情况使用,否则会消耗系统的资源

   -Map控件:在使用时,首先要申请授权验证密钥 显示模式设置有Road、Arial

          -显示缩放按钮:ZoomBarVisibility属性

          -显示比例尺:ScaleVisibility属性 

          -加标记:用到Pushpin类

     //为地图加标记

            Pushpin pin = new Pushpin();

            pin.Location = new GeoCoordinate(30.3441333,120.342155132);

            pin.Width = 200;

            pin.Height = 200;

            pin.Content = "济南";

            pin.Background = new SolidColorBrush(Colors.Red);

            mymap.Children.Add(pin);

          -绘制多变型区域:用到MapPolygon类 实例化 设置Locations属性即可

     //在地图上绘制多边形

            MapPolygon polygon = new MapPolygon();

            polygon.Fill = new SolidColorBrush(Colors.Red);

            polygon.Stroke = new SolidColorBrush(Colors.Yellow);

            polygon.StrokeThickness = 5;

            polygon.Opacity = 0.7;

            polygon.Locations = new LocationCollection()

            {

                new GeoCoordinate(30,120),

                new GeoCoordinate(30,130),

                new GeoCoordinate(30,160),

                new GeoCoordinate(30,140)

            };

            mymap.Children.Add(polygon);

   -绘制多边线:用到MapPolyline 实例化 设置Stroke属性和Locatatoins

     //在地图上绘制多边线

            MapPolyline polyline = new MapPolyline();

            polyline.Stroke = new SolidColorBrush(Colors.Red);

            polyline.StrokeThickness = 5;

            polyline.Opacity = 0.5;

            polyline.Locations = new LocationCollection()

            {

                new GeoCoordinate(30.3424242,120.3432444),

                new GeoCoordinate(30.3424242,120.3432444)

            };

            mymap.Children.Add(polyline);

          -在地图上添加图片

      //在地图上添加图片

            Image image = new Image();

            image.Width = 100;

            image.Height = 100;

            image.Source = new BitmapImage(new Uri("Images/Pic1.jpg",UriKind.Relative));

            MapLayer imagelayer = new MapLayer();

            imagelayer.AddChild(image,new GeoCoordinate(30,120),PositionOrigin.BottomLeft);

            mymap.Children.Add(imagelayer);

posted @ 2011-11-14 14:46  zhangze  阅读(1017)  评论(0编辑  收藏  举报