when I update Xamarin forms to 3.2.0 or higher, I am getting the following error:
Error Position 68:29. Signature (return type) of EventHandler
"TimeToSport.Views.ItemsPage.OnCanvasViewPaintSurfaceAsync" doesn't match
the event type TimeToSport
E:\Xamarin Projects\TimeToSport_master\TimeToSport\TimeToSport\Views\Main\ItemsPage.xaml 68
The error is coming from this code (xaml):
<skia:SKCanvasView x:Name="canvas"
PaintSurface="OnCanvasViewPaintSurfaceAsync"
Grid.Row="2"
/>
In the CS file:
SKCanvas canvas = surface.Canvas;
When I was working with Xamarin forms version 3.1.0, I didn't get this error and everything worked. However, I have to update Xamarin forms for some new features I need to use.
How can I fix this error?
EDIT:
OnCanvasViewPaintSurfaceAsync:
async Task OnCanvasViewPaintSurfaceAsync(object sender, SKPaintSurfaceEventArgs args1)
{
args = args1;
await drawGaugeAsync();
}
public async Task drawGaugeAsync()
{
// Radial Gauge Constants
int uPadding = 130;
int side = 370;
int radialGaugeWidth = 20;
// Line TextSize inside Radial Gauge
int lineSize1 = 220;
int lineSize2 = 70;
int lineSize3 = 80;
// Line Y Coordinate inside Radial Gauge
int lineHeight1 = 175;
int lineHeight2 = 275;
int lineHeight3 = 350;
// Start & End Angle for Radial Gauge
//float startAngle = (360/24)*23+90;
float sweepAngle = 360;
try
{
// Getting Canvas Info
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;
progressUtils.setDevice(info.Height, info.Width);
canvas.Clear();
//canvas.DrawColor(SKColor.Parse("#2196F3")); //Background upper
// Getting Device Specific Screen Values
// -------------------------------------------------
// Top Padding for Radial Gauge
float upperPadding = progressUtils.getFactoredHeight(uPadding);
/* Coordinate Plotting for Radial Gauge
*
* (X1,Y1) ------------
* | (XC,YC) |
* | . |
* Y | |
* | |
* ------------ (X2,Y2))
* X
*
*To fit a perfect Circle inside --> X==Y
* i.e It should be a Square
*/
// Xc & Yc are center of the Circle
int Xc = info.Width / 2;
float Yc = progressUtils.getFactoredHeight(side);
float Yc2 = progressUtils.getFactoredHeight(445);
// X1 Y1 are lefttop cordiates of rectange
int X1 = (int)(Xc - Yc);
int Y1 = (int)(Yc - Yc + upperPadding + 9); //+55
int X12 = (int)(Xc - Yc2);
int Y12 = (int)(Yc2 - Yc2 + upperPadding - 22.5);
// X2 Y2 are rightbottom cordiates of rectange
int X2 = (int)(Xc + Yc);
int Y2 = (int)(Yc + Yc + upperPadding + 9); //+55
int X22 = (int)(Xc + Yc2);
int Y22 = (int)(Yc2 + Yc2 + upperPadding - 22.5);
// Empty Gauge Styling // basis
SKPaint paint1 = new SKPaint
{
Style = SKPaintStyle.Stroke,
IsAntialias = true,
Color = Color.FromHex("#f7f7f7").ToSKColor(), // Colour of Radial Gauge
StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth - 10), // Width of Radial Gauge
StrokeCap = SKStrokeCap.Butt // Round Corners for Radial Gauge
};
// Filled Gauge Styling // slaap
SKPaint paint2 = new SKPaint
{
Style = SKPaintStyle.Stroke,
IsAntialias = true,
Color = Color.FromHex("#183f7c").ToSKColor(), // Overlay Colour of Radial Gauge
StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth + 10), // Overlay Width of Radial Gauge
StrokeCap = SKStrokeCap.Butt // Round Corners for Radial Gauge
};
// Empty Gauge Styling // voeding
SKPaint paint3 = new SKPaint
{
Style = SKPaintStyle.Stroke,
IsAntialias = true,
Color = Color.FromHex("#c45256").ToSKColor(), // Colour of Radial Gauge
StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth + 10), // Width of Radial Gauge
StrokeCap = SKStrokeCap.Butt // Round Corners for Radial Gauge
};
// Filled Gauge Styling // sport
SKPaint paint4 = new SKPaint
{
Style = SKPaintStyle.Stroke,
IsAntialias = true,
Color = Color.FromHex("#5bd363").ToSKColor(), // Overlay Colour of Radial Gauge
StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth + 15), // Overlay Width of Radial Gauge
StrokeCap = SKStrokeCap.Butt // Round Corners for Radial Gauge
};
SKPaint paint5 = new SKPaint // voeding na sport
{
Style = SKPaintStyle.Stroke,
IsAntialias = true,
Color = Color.FromHex("#c45256").ToSKColor(), // Overlay Colour of Radial Gauge
StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth + 10), // Overlay Width of Radial Gauge
StrokeCap = SKStrokeCap.Butt // Round Corners for Radial Gauge
};
SKPaint paint6 = new SKPaint // lokale tijd
{
Style = SKPaintStyle.Stroke,
IsAntialias = true,
Color = Color.FromHex("#ffb342").ToSKColor(), // Overlay Colour of Radial Gauge
StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth + 25), // Overlay Width of Radial Gauge
StrokeCap = SKStrokeCap.Butt // Round Corners for Radial Gauge
};
SKPaint paint7 = new SKPaint // vierkant 1
{
Style = SKPaintStyle.StrokeAndFill,
IsAntialias = true,
Color = Color.FromHex("#ffffff").ToSKColor(), // Overlay Colour of Radial Gauge
StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth + 60), // Overlay Width of Radial Gauge
StrokeCap = SKStrokeCap.Round // Round Corners for Radial Gauge
};
// Defining boundaries for Gauge
SKRect rect = new SKRect(X1, Y1, X2, Y2);
SKRect rectBackground1 = new SKRect(X1 - 75, Y1 - 75, X2 + 75, Y2 + 75);
SKRect rect2 = new SKRect(X12, Y12, X22, Y22);
//canvas.DrawRect(rect, paint1);
//canvas.DrawOval(rect, paint1);
// Rendering Empty Gauge
SKPath path7 = new SKPath();
//path7.AddRoundedRect(rectBackground1, 5, 5, SKPathDirection.Clockwise);
//canvas.DrawPath(path7, paint7);
SKPath path1 = new SKPath();
path1.AddArc(rect, -90, sweepAngle);
canvas.DrawPath(path1, paint1);
// Rendering Filled Gauge
SKPath path2 = new SKPath();
path2.AddArc(rect, (360 / 24) * 23 - 90, (float)sweepAngleSlider.Value);
canvas.DrawPath(path2, paint2);
SKPath path3 = new SKPath();
path3.AddArc(rect, (360 / 24) * 8.50f - 90, (float)sweepAngleSlider2.Value);
canvas.DrawPath(path3, paint3);
SKPath path4 = new SKPath();
path4.AddArc(rect, (360 / 24) * 9.25f - 90, (float)sweepAngleSlider3.Value);
canvas.DrawPath(path4, paint4);
SKPath path5 = new SKPath();
path5.AddArc(rect, (360 / 24) * 12f - 90, (float)sweepAngleSlider4.Value);
canvas.DrawPath(path5, paint5);
//lokale tijd onderaan
/*// Rendering Empty Gauge
SKPath path3 = new SKPath();
path3.AddArc(rect2, startAngle, sweepAngle);
canvas.DrawPath(path3, paint3);
// Rendering Filled Gauge
SKPath path4 = new SKPath();
path4.AddArc(rect2, startAngle, (float)sweepAngleSlider2.Value);
canvas.DrawPath(path4, paint4);*/
//---------------- Drawing Text Over Gauge ---------------------------
// frequentie dagen
using (SKPaint skPaint = new SKPaint())
{
skPaint.Style = SKPaintStyle.Fill;
skPaint.IsAntialias = true;
skPaint.Color = SKColor.Parse("#2b2b2b");
skPaint.TextAlign = SKTextAlign.Center;
skPaint.TextSize = progressUtils.getFactoredHeight(lineSize1);
skPaint.Typeface = SKTypeface.FromFamilyName(
"Arial",
SKFontStyleWeight.Bold,
SKFontStyleWidth.Normal,
SKFontStyleSlant.Upright);
// Drawing Achieved Minutes Over Radial Gauge
if (sw_listToggle.IsToggled)
canvas.DrawText(/*monthlyWorkout +*/ "3", Xc, Yc + progressUtils.getFactoredHeight(lineHeight1), skPaint);
else
canvas.DrawText(/*dailyWorkout + */ "3-4", Xc, Yc + progressUtils.getFactoredHeight(lineHeight1), skPaint);
}
// "per week"
using (SKPaint skPaint = new SKPaint())
{
skPaint.Style = SKPaintStyle.Fill;
skPaint.IsAntialias = true;
skPaint.Color = SKColor.Parse("#424242");
skPaint.TextAlign = SKTextAlign.Center;
skPaint.TextSize = progressUtils.getFactoredHeight(55);
//ff een testje
canvas.DrawText(Application.Current.Properties["geslacht"].ToString(), Xc, Yc + progressUtils.getFactoredHeight(lineHeight2), skPaint);
canvas.DrawText("06", X2 + 80, (Y1 + Y2) / 2 + 22, skPaint);
canvas.DrawText("12", Xc, Y2 + 115, skPaint);
canvas.DrawText("18", X1 - 100, (Y1 + Y2) / 2 + 22, skPaint);
canvas.DrawText("00", Xc, Y1 - 60, skPaint);
}
// Goal Minutes Text Styling
using (SKPaint skPaint = new SKPaint())
{
skPaint.Style = SKPaintStyle.Fill;
skPaint.IsAntialias = true;
skPaint.Color = SKColor.Parse("#e2797a");
skPaint.TextAlign = SKTextAlign.Center;
skPaint.TextSize = progressUtils.getFactoredHeight(lineSize3);
// Drawing Text Over Radial Gauge
// if (sw_listToggle.IsToggled)
//canvas.DrawText("Goal " + goal + " Min", Xc, Yc + progressUtils.getFactoredHeight(lineHeight3), skPaint);
//else
//{
//canvas.DrawText("Goal " + goal / 30 + " Min", Xc, Yc + progressUtils.getFactoredHeight(lineHeight3), skPaint);
//}
}
sportenTijdText1 = "09:15";
etenVoorTijdText1 = "08:30";
etenNaTijdText1 = "09:00";
slapenTijdText1 = "23:00";
sportenTijdText2 = "10:45";
etenVoorTijdText2 = "12:00";
etenNaTijdText2 = "12:30";
slapenTijdText2 = "08:00";
SportKnop.Text = sportenTijdText1 + " - Sporten - " + sportenTijdText2;
VoedingVoorKnop.Text = etenVoorTijdText1 + " - Eten - " + etenNaTijdText1;
VoedingNaKnop.Text = etenVoorTijdText1 + " - Eten - " + etenNaTijdText2;
SlaapKnop.Text = slapenTijdText1 + " - Slapen - " + slapenTijdText2;
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
Device.BeginInvokeOnMainThread(() => tijd.Text = DateTime.Now.ToString("HH.mm"));
Device.BeginInvokeOnMainThread(() => TijdKnop.Text = "Huidige tijd - " + DateTime.Now.ToString("HH:mm"));
return true;
});
SKPath path6 = new SKPath();
path6.AddArc(rect, (360 / 24) * float.Parse(tijd.Text, CultureInfo.InvariantCulture.NumberFormat) + -91.5f, (float)sweepAngleSlider5.Value);
canvas.DrawPath(path6, paint6);
}
catch (Exception e)
{
Debug.WriteLine(e.StackTrace);
}
}
From recent Xamarin forms update code behind dont support
Task
return type as signatures for event handlers.Remove
Task
and replace it withvoid
Update :
public async Task drawGaugeAsync()
can returnTask