如何在 Xamarin 应用程序中构建斜虚线
How can I build slanted dashed line in Xamarin application
我想在我的应用程序中显示一条斜虚线,看起来像
this。在 xamarin 中使用 Line API 我能够创建虚线,但我没有任何运气使每个破折号倾斜。我还查看了 Xamarin 的 skiasharp 库,但没有找到任何可以帮助倾斜的东西。
@jason 感谢您的回复,我非常专注于获得您建议的“倾斜虚线”,但我从来没有想过。虽然现在我的问题有了解决方案。
public partial class SlantedDashedView : ContentView
{
private readonly SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Fill,
Color = Color.Red.ToSKColor()
};
private readonly SKRect rect = new SKRect
{
Location = new SKPoint(0, 0),
Size = new SKSize(25, 30)
};
public SlantedDashedView()
{
InitializeComponent();
mainCanvas.InvalidateSurface();
}
private void MainCanvas_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
SKImageInfo info = e.Info;
SKSurface surface = e.Surface;
SKCanvas canvas = surface.Canvas;
int currentY = 0;
canvas.Skew(0, -1);
while (currentY < info.Height)
{
canvas.DrawRect(rect, paint);
currentY += 45;
canvas.Translate(0, 45);
}
}
}
Here是结果
我想在我的应用程序中显示一条斜虚线,看起来像 this。在 xamarin 中使用 Line API 我能够创建虚线,但我没有任何运气使每个破折号倾斜。我还查看了 Xamarin 的 skiasharp 库,但没有找到任何可以帮助倾斜的东西。
@jason 感谢您的回复,我非常专注于获得您建议的“倾斜虚线”,但我从来没有想过。虽然现在我的问题有了解决方案。
public partial class SlantedDashedView : ContentView
{
private readonly SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Fill,
Color = Color.Red.ToSKColor()
};
private readonly SKRect rect = new SKRect
{
Location = new SKPoint(0, 0),
Size = new SKSize(25, 30)
};
public SlantedDashedView()
{
InitializeComponent();
mainCanvas.InvalidateSurface();
}
private void MainCanvas_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
SKImageInfo info = e.Info;
SKSurface surface = e.Surface;
SKCanvas canvas = surface.Canvas;
int currentY = 0;
canvas.Skew(0, -1);
while (currentY < info.Height)
{
canvas.DrawRect(rect, paint);
currentY += 45;
canvas.Translate(0, 45);
}
}
}
Here是结果