【问题标题】:xamarin forms absolute layout draw shape based on coordinatexamarin 基于坐标形成绝对布局绘制形状
【发布时间】:2017-12-11 00:57:28
【问题描述】:

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

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

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

【问题讨论】:

标签: c# xaml xamarin xamarin.forms


【解决方案1】:

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

在绘制点的路径方面,这是一个非常简单的示例:

绘制 NGraphics 列表的 NControlView 子类PathOp:

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&lt;PathOp&gt;

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

Xaml:

从此answer 获取 XAML 并添加:

<nc:PathControl x:Name="pathControl" AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All" />    

你可以制作这个:

有了更多的矢量工作,像这样:

其他 NControl/NGraphics 答案/示例:

回复:Xamarin.Forms - How To Achieve 45 deg. Angled Background Color

回复:Creating completeness meter (Status display) in Xamarin

回复:Pop Up in xamarin.forms

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 2017-12-11
    • 2012-02-24
    • 2023-04-05
    • 1970-01-01
    相关资源
    最近更新 更多