Xamarin基于坐标形成绝对布局绘制形状 [英] xamarin forms absolute layout draw shape based on coordinate

查看:361
本文介绍了Xamarin基于坐标形成绝对布局绘制形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在绝对布局上使用坐标来标记一些点,即:

I'm using coordinates on absolute layout to mark some points i.e.:

new Point() { X = 0, Y = 0 };
new Point() { X = 0, Y = 300 };
new Point() { X = 200, Y = 0 };

如何从点到点画一条线,将它们连接起来,在这种情况下为三角形?

How to draw a lines from point to point, connect them, in this case triangle shape?

推荐答案

SkiaSharp很好,但是如果您不需要Skia的所有功能,则本机库的开销,增加的应用程序大小,初始化时间和内存消耗NControl/NGraphics可以避免.

SkiaSharp is great, but if you do not need all of Skia's features, the overhead of native libraries, increased app size, init times, and memory consumption can be avoided with NControl/NGraphics.

就绘制点的路径而言,这是一个非常简单的示例:

In terms of drawing a path of points, here is a really quick example:

public class PathControl : NControlView
{
    public IEnumerable<PathOp> Path { get; set; }

    public override void Draw(ICanvas canvas, Rect rect)
    {
        if (Path != null)
            canvas.DrawPath(Path, new Pen(Colors.Red, 5));
    }
}

运行时分配:

然后您可以在运行时分配IEnumerable<PathOp>:

pathControl.Path = new PathOp[] {
    new MoveTo (40, 60),
    new LineTo (120, 60),
    new LineTo (80, 30),
    new ClosePath ()
};
pathControl.Invalidate();

Xaml:

从此

您可以生成此文件:

通过更多的矢量工作,像这样:

With more vector work, something like this:

re: Xamarin.Forms -如何达到45度.有角度的背景颜色

re:在Xamarin中创建完整性表(状态显示)

re:弹出xamarin.forms

这篇关于Xamarin基于坐标形成绝对布局绘制形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆