开发者

system.Drawing.Drawing2d.GraphicsPath

I have a c# class library that supports Silverlight4 as well.

The problem is , I need to use System.Drawing.Drawing2d.GraphicsPath in my code. for drawing a shape. but it is not there in silverlight. Can anyone suggest me an al开发者_开发百科ternative?

Thanks in advance.

Regards, James


take a look at http://www.c-sharpcorner.com/UploadFile/mahesh/PathInSL03252009005946AM/PathInSL.aspx

Snippet XAML:

<Path Stroke="Black" StrokeThickness="4" 
        Data="M 80,200 A 100,50 45 1 0 100,50" />

Snippet Dynamic:

public void CreateAPath()

{

    // Create a blue and a black Brush

    SolidColorBrush blueBrush = new SolidColorBrush();

    blueBrush.Color = Colors.Blue;

    SolidColorBrush blackBrush = new SolidColorBrush();

    blackBrush.Color = Colors.Black;



    // Create a Path with black brush and blue fill

    Path bluePath = new Path();

    bluePath.Stroke = blackBrush;

    bluePath.StrokeThickness = 3;

    bluePath.Fill = blueBrush;



    // Create a line geometry

    LineGeometry blackLineGeometry = new LineGeometry();

    blackLineGeometry.StartPoint = new Point(20, 200);

    blackLineGeometry.EndPoint = new Point(300, 200);



    // Create an ellipse geometry

    EllipseGeometry blackEllipseGeometry = new EllipseGeometry();

    blackEllipseGeometry.Center = new Point(80, 150);

    blackEllipseGeometry.RadiusX = 50;

    blackEllipseGeometry.RadiusY = 50;



    // Create a rectangle geometry

    RectangleGeometry blackRectGeometry = new RectangleGeometry();

    Rect rct = new Rect();

    rct.X = 80;

    rct.Y = 167;

    rct.Width = 150;

    rct.Height = 30;

    blackRectGeometry.Rect = rct;



    // Add all the geometries to a GeometryGroup.

    GeometryGroup blueGeometryGroup = new GeometryGroup();

    blueGeometryGroup.Children.Add(blackLineGeometry);

    blueGeometryGroup.Children.Add(blackEllipseGeometry);

    blueGeometryGroup.Children.Add(blackRectGeometry);



    // Set Path.Data

    bluePath.Data = blueGeometryGroup;



    LayoutRoot.Children.Add(bluePath);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜