我想在我的應用程式中顯示一條傾斜的虛線,看起來像 這樣。在 xamarin 中使用 Line API 我能夠創建虛線,但我沒有讓每個虛線傾斜。我還查看了 Xamarin 的skiasharp 庫,但沒有找到任何可以幫助傾斜的東西。
uj5u.com熱心網友回復:
@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);
}
}
}
這是結果
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/451007.html
上一篇:單擊Pin時嘗試從API加載資料(CustomMap)錯誤:指定的轉換無效。-xamarin.forms.maps
