|
private void CustomizeLayoutBorder()
{
Grid grid = ((this.Children[0] as StackLayout).Children[0] as Grid);
int row = Grid.GetRow(grid.Children[3]), column = Grid.GetColumn(grid.Children[3]);
int rowSpan = Grid.GetRowSpan(grid.Children[3]),columnSpan = Grid.GetColumnSpan(grid.Children[3]);
grid.Children.RemoveAt(3);
SKCanvasView canvasView = new SKCanvasView();
canvasView.PaintSurface += OnCanvasViewPaintSurface;
grid.Children.Add(canvasView);
Grid.SetRow(canvasView, row);
Grid.SetColumn(canvasView, column);
Grid.SetRowSpan(canvasView, rowSpan);
Grid.SetColumnSpan(canvasView, columnSpan);
}
private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKCanvas canvas = (args.Surface).Canvas;
canvas.Clear();
SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = SKColors.Black,
StrokeWidth = 5,
StrokeCap = SKStrokeCap.Butt,
PathEffect = SKPathEffect.CreateDash(new float[] { 15, 15 }, 20)
};
SKPath path = new SKPath();
path.LineTo((args.Info).Width, 0);
canvas.DrawPath(path, paint);
} |
|
public class LineView : ContentView
{
public static readonly BindableProperty StrokeDashArrayProperty =
BindableProperty.Create(nameof(StrokeDashArray), typeof(DoubleCollection), typeof(LineView), null, BindingMode.Default, null, StrokeDashArrayValueChanged);
private static void StrokeDashArrayValueChanged(BindableObject bindable, object oldValue, object newValue)
{
var lineView = bindable as LineView;
if(lineView.line != null)
{
lineView.line.StrokeDashArray = newValue as DoubleCollection;
}
}
public DoubleCollection StrokeDashArray
{
get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); }
set { SetValue(StrokeDashArrayProperty, value); }
}
private Line line { get; set; }
public LineView()
{
line = new Line();
line.Stroke = Brush.Black;
line.StrokeThickness = 2d;
var stack = new StackLayout();
stack.Children.Add(line);
this.Content = stack;
}
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (width <= 0 || height <= 0) return;
line.X1 = 0;
line.X2 = width;
line.Y1 = 0;
line.Y2 = 0;
}
} |