Dee  Jacobi

Dee Jacobi


.NET MAUI: How to Draw 2D Graphics in GraphicsView

In this article we will learn together How to draw 2D graphics in GraphicsView of .NET MAUI. If you need to draw 2D graphical objects in your application without a platform handler in .NET MAUI, then you can use the cross-platform graphics canvas, GraphicsView, that .NET MAUI provides. This GraphicsView can be accessed using the Microsoft.Maui.Graphics namespace. This canvas supports drawing and painting shapes and images, compositing operations, and transforming graphical object.

GraphicsView defines a Drawable property, of type IDrawable, that is responsible for drawing your 2D objects within the Draw() method. The Draw() method will be called each time the GraphicsView is invalidated.

Class Diagram of GraphicsView

GraphicsView Class Diagram

In this blog, let’s see how to draw 2D graphics using the GraphicsView canvas in your .NET MAUI application.

Creating a GraphicsView

The GraphicsView control should define the IDrawable interface that specifies the drawable content. So, first create a class named GraphicsDrawable that is inherited from the IDrawable interface and then implement its Draw method.

Refer to the following code example.

namespace _2DGraphicsDrawing;
public class GraphicsDrawable : IDrawable
   public void Draw(ICanvas canvas, RectF dirtyRect)
      // Drawing code goes here

The Draw method has the following two arguments:

  • ICanvas: The drawing canvas that contains the abstraction of native canvas APIs to draw graphical objects.
  • RectF: A structure that defines the size and location data of the drawing canvas.

The following code example shows how to add the GraphicsView control to a .NET MAUI app and assign the IDrawable object.

<ContentPage xmlns=""
  <local:GraphicsDrawable x:Key="drawable"/>
  <GraphicsView Drawable="{StaticResource drawable}"
                WidthRequest="500" />

With the setup to draw in a .NET MAUI application completed, lets focus on drawing simple shapes and string values.

Drawing a line

You can draw a line on the ICanvas interface using the DrawLine method. This method requires four arguments of type float that specify the x and y coordinates of start and stop points of the line.

The following code example shows how to draw a simple line using the DrawLine method.

public class GraphicsDrawable : IDrawable
  public void Draw(ICanvas canvas, RectF dirtyRect)
    canvas.StrokeColor = Colors.Red;
    canvas.StrokeSize = 6;
    canvas.DrawLine(10, 10, 100, 100);
}Drawing a Simple Line Using the GraphicsView Canvas in .NET MAUI

Drawing an ellipse

To draw an ellipse or a circle on the ICanvas, use the DrawEllipse method. The DrawEllipse method takes four arguments, x, y, width, and height, of type float, that represent the starting point and size (width and height) of the ellipse.

Note: To draw a circle, specify the same values to the width and height arguments in the DrawEllipse method.

Refer to the following code example.

public void Draw(ICanvas canvas, RectF dirtyRect)
   canvas.StrokeColor = Colors.Red;
   canvas.StrokeSize = 4;
   canvas.DrawEllipse(10, 10, 100, 50);
}Drawing an Ellipse Using the GraphicsView Canvas in .NET MAUI


To draw a filled ellipse, use the FillEllipse method with the same set of arguments.

Drawing a rectangle

We can easily draw rectangles and squares on the ICanvas using the DrawRectangle method. This method takes x, y, width, and height arguments, of type float, that represent the start position and size of the rectangle or square.

Note: To draw a square, specify the same values in the width and height arguments in the DrawRectangle method.

Refer to the following code example to draw a rectangle.

public void Draw(ICanvas canvas, RectF dirtyRect)
  canvas.StrokeColor = Colors.Red;
  canvas.StrokeSize = 4;
  canvas.DrawRectangle(10, 10, 100, 50);
}Drawing a Rectangle Using the GraphicsView Canvas in .NET MAUI


A filled rectangle can be drawn using the FillRectangle method on the ICanvas with the same set of arguments.

Drawing an arc

Let’s draw an arc on the ICanvas using the DrawArc method. To do so, we require the x, y, width, height, startAngle, and endAngle arguments, of type float; and clockwise and closed arguments, of type bool.

Refer to the following code example.

public void Draw(ICanvas canvas, RectF dirtyRect)
  canvas.StrokeColor = Colors.Red;
  canvas.StrokeSize = 4;
  canvas.DrawArc(10, 10, 100, 100, 0, 180, true, false);
}Drawing an Arc Using the GraphicsView Canvas in .NET MAUI

A filled arc can be drawn using the FillArc method on ICanvas with the same set of arguments.

Drawing a path

A path is a collection of one or more contours that consists of straight lines, quadratic curves, and cubic curves.

We can use the paths to draw curves and complex shapes on the ICanvas using the DrawPath method, which requires a PathF argument.

A contour generally begins with a call to the PathF.MoveTo method, which establishes a point at the beginning of the contour and an initial current point. You can then call the following methods to continue the contour with a line or curve shape:

  • LineTo: Adds a straight line to the path.
  • AddArc: Adds an arc.
  • CurveTo: Adds a cubic Bezier spline.
  • QuadTo: Adds a quadratic Bezier spline.

The following code example shows how to draw a path.

Public void Draw (Icanvas canvas, RectF dirtyRect)
  PathF path = new PathF();
  path.MoveTo(40, 10);
  path.LineTo(70, 80);
  path.LineTo(10, 50);
  canvas.StrokeColor = Colors.Red;
  canvas.StrokeSize = 6;
}Drawing a Path Using the GraphicsView Canvas in .NET MAUI

A filled path can be drawn using the FillPath method in ICanvas.

Drawing a string

Now, let’s see how to draw strings on ICanvas using the DrawString method. We can define the appearance of each string by setting the Font, FontColor, and FontSize properties of ICanvas. To align the strings, specify the horizontal and vertical alignment options in the DrawString method to perform alignment within the bounding box.

The following code example shows how to draw strings.

Public void Draw(Icanvas canvas, RectF dirtyRect)
   canvas.FontColor = Colors.Red;
   canvas.FontSize = 18;
   canvas.DrawString(“Text is left aligned.”, 20, 20, 380, 100, HorizontalAlignment.Left, VerticalAlignment.Top);
   canvas.DrawString(“Text is centered.”, 20, 60, 380, 100, HorizontalAlignment.Center, VerticalAlignment.Top);
   canvas.DrawString(“Text is right aligned.”, 20, 100, 380, 100, HorizontalAlignment.Right, VerticalAlignment.Top);
}Drawing Strings Using the GraphicsView Canvas in .NET MAUI

Drawing free hand signatures using the GraphicsView in .NET MAUI

In the previous examples, we learned how to use the GraphicsView control to create simple shapes and text.

Now, let’s see how to create a signature in your .NET MAUI app.

Note: To get the realistic look and feel of a handwritten signature, use the Syncfusion .NET MAUI SignaturePad control.

Follow these steps to capture and freehand draw using the GraphicsView control:

Step 1: Create the SignatureView class, extended from the GraphicsView control.

public class SignatureView : GraphicsView

Step 2: Then, create an object of type GraphicsDrawable and assign it to the Drawable property of the SignatureView.

public SignatureView()
  graphicsDrawable = new GraphicsDrawable();
  this.Drawable = graphicsDrawable;

Step 3: The GraphicsView provides the events support to detect interaction with the touch pointers such as start, drag, and end interactions. Using this support, we can get the touch interaction points on each move. Now, call the Invalidate() method within the event to draw the signature based on every touch movement in the drawable part.

Public SignatureView()
  this.StartInteraction += SignatureView_StartInteraction;
  this.DragInteraction += SignatureView_DragInteraction;
  this.EndInteraction += SignatureView_EndInteraction;
private void SignatureView_DragInteraction(object sender, TouchEventArgs e)
private void SignatureView_StartInteraction(object sender, TouchEventArgs e)
    graphicsDrawable.StartPoint = e.Touches[0];

Step 4: Draw signatures using the Draw method, which has ICanvas and view bounds. Using this method, you can also draw a background for view bounds and signatures based on the captured interaction points.

public void Draw(ICanvas canvas, RectF dirtyRect)
   canvas.FillColor = Colors.CornflowerBlue;
   PathF path = new PathF();
   if (DragPoints?.Count > 0)
      path.MoveTo(StartPoint.X, StartPoint.Y);
      foreach (var point in DragPoints)
      canvas.StrokeColor = Colors.Red;
      canvas.StrokeSize = 2;

That’s it! You can now create your signatures with the help of the .NET MAUI 2D graphics canvas. Refer to the following GIF image.

Drawing a Signature Using the GraphicsView Canvas in .NET MAUI

Drawing a Signature Using the GraphicsView Canvas in .NET MAUI

GitHub reference

For more details, refer to the complete code example for drawing signatures using the GraphicsView in .NET MAUI.


Thanks for reading! In this blog post, we have seen how to draw 2D graphics in your .NET MAUI applications using the GraphicsView canvas. Try out the procedures in this blog and leave your feedback in the comments section below!

Syncfusion .NET MAUI controls were built from scratch using .NET MAUI, so they feel like framework controls. They are fine-tuned to work with a huge volume of data. Use them to build better cross-platform mobile and desktop apps!

Original article sourced at:


What is GEEK

Buddha Community

.NET MAUI: How to Draw 2D Graphics in GraphicsView
Einar  Hintz

Einar Hintz


jQuery Ajax CRUD in ASP.NET Core MVC with Modal Popup

In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.

To demonstrate CRUD operations – insert, update, delete and retrieve, the project will be dealing with details of a normal bank transaction. GitHub repository for this demo project :

Sub-topics discussed :

  • Form design for insert and update operation.
  • Display forms in modal popup dialog.
  • Form post using jQuery Ajax.
  • Implement MVC CRUD operations with jQuery Ajax.
  • Loading spinner in .NET Core MVC.
  • Prevent direct access to MVC action method.

Create ASP.NET Core MVC Project

In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N).

From new project window, Select Asp.Net Core Web Application_._

Image showing how to create ASP.NET Core Web API project in Visual Studio.

Once you provide the project name and location. Select Web Application(Model-View-Controller) and uncheck HTTPS Configuration. Above steps will create a brand new ASP.NET Core MVC project.

Showing project template selection for .NET Core MVC.

Setup a Database

Let’s create a database for this application using Entity Framework Core. For that we’ve to install corresponding NuGet Packages. Right click on project from solution explorer, select Manage NuGet Packages_,_ From browse tab, install following 3 packages.

Showing list of NuGet Packages for Entity Framework Core

Now let’s define DB model class file – /Models/TransactionModel.cs.

public class TransactionModel
    public int TransactionId { get; set; }

    [Column(TypeName ="nvarchar(12)")]
    [DisplayName("Account Number")]
    [Required(ErrorMessage ="This Field is required.")]
    [MaxLength(12,ErrorMessage ="Maximum 12 characters only")]
    public string AccountNumber { get; set; }

    [Column(TypeName ="nvarchar(100)")]
    [DisplayName("Beneficiary Name")]
    [Required(ErrorMessage = "This Field is required.")]
    public string BeneficiaryName { get; set; }

    [Column(TypeName ="nvarchar(100)")]
    [DisplayName("Bank Name")]
    [Required(ErrorMessage = "This Field is required.")]
    public string BankName { get; set; }

    [Column(TypeName ="nvarchar(11)")]
    [DisplayName("SWIFT Code")]
    [Required(ErrorMessage = "This Field is required.")]
    public string SWIFTCode { get; set; }

    [Required(ErrorMessage = "This Field is required.")]
    public int Amount { get; set; }

    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime Date { get; set; }


Here we’ve defined model properties for the transaction with proper validation. Now let’s define  DbContextclass for EF Core. core article core #add loading spinner in core core crud without reloading core jquery ajax form core modal dialog core mvc crud using jquery ajax core mvc with jquery and ajax core popup window #bootstrap modal popup in core mvc. bootstrap modal popup in core #delete and viewall in core #jquery ajax - insert #jquery ajax form post #modal popup dialog in core #no direct access action method #update #validation in modal popup

Dylan  Iqbal

Dylan Iqbal


Matplotlib Cheat Sheet: Plotting in Python

This Matplotlib cheat sheet introduces you to the basics that you need to plot your data with Python and includes code samples.

Data visualization and storytelling with your data are essential skills that every data scientist needs to communicate insights gained from analyses effectively to any audience out there. 

For most beginners, the first package that they use to get in touch with data visualization and storytelling is, naturally, Matplotlib: it is a Python 2D plotting library that enables users to make publication-quality figures. But, what might be even more convincing is the fact that other packages, such as Pandas, intend to build more plotting integration with Matplotlib as time goes on.

However, what might slow down beginners is the fact that this package is pretty extensive. There is so much that you can do with it and it might be hard to still keep a structure when you're learning how to work with Matplotlib.   

DataCamp has created a Matplotlib cheat sheet for those who might already know how to use the package to their advantage to make beautiful plots in Python, but that still want to keep a one-page reference handy. Of course, for those who don't know how to work with Matplotlib, this might be the extra push be convinced and to finally get started with data visualization in Python. 

You'll see that this cheat sheet presents you with the six basic steps that you can go through to make beautiful plots. 

Check out the infographic by clicking on the button below:

Python Matplotlib cheat sheet

With this handy reference, you'll familiarize yourself in no time with the basics of Matplotlib: you'll learn how you can prepare your data, create a new plot, use some basic plotting routines to your advantage, add customizations to your plots, and save, show and close the plots that you make.

What might have looked difficult before will definitely be more clear once you start using this cheat sheet! Use it in combination with the Matplotlib Gallery, the documentation.


Matplotlib is a Python 2D plotting library which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms.

Prepare the Data 

1D Data 

>>> import numpy as np
>>> x = np.linspace(0, 10, 100)
>>> y = np.cos(x)
>>> z = np.sin(x)

2D Data or Images 

>>> data = 2 * np.random.random((10, 10))
>>> data2 = 3 * np.random.random((10, 10))
>>> Y, X = np.mgrid[-3:3:100j, -3:3:100j]
>>> U = 1 X** 2 + Y
>>> V = 1 + X Y**2
>>> from matplotlib.cbook import get_sample_data
>>> img = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))

Create Plot

>>> import matplotlib.pyplot as plt


>>> fig = plt.figure()
>>> fig2 = plt.figure(figsize=plt.figaspect(2.0))


>>> fig.add_axes()
>>> ax1 = fig.add_subplot(221) #row-col-num
>>> ax3 = fig.add_subplot(212)
>>> fig3, axes = plt.subplots(nrows=2,ncols=2)
>>> fig4, axes2 = plt.subplots(ncols=3)

Save Plot 

>>> plt.savefig('foo.png') #Save figures
>>> plt.savefig('foo.png',  transparent=True) #Save transparent figures

Show Plot


Plotting Routines 

1D Data 

>>> fig, ax = plt.subplots()
>>> lines = ax.plot(x,y) #Draw points with lines or markers connecting them
>>> ax.scatter(x,y) #Draw unconnected points, scaled or colored
>>> axes[0,0].bar([1,2,3],[3,4,5]) #Plot vertical rectangles (constant width)
>>> axes[1,0].barh([0.5,1,2.5],[0,1,2]) #Plot horiontal rectangles (constant height)
>>> axes[1,1].axhline(0.45) #Draw a horizontal line across axes
>>> axes[0,1].axvline(0.65) #Draw a vertical line across axes
>>> ax.fill(x,y,color='blue') #Draw filled polygons
>>> ax.fill_between(x,y,color='yellow') #Fill between y values and 0

2D Data 

>>> fig, ax = plt.subplots()
>>> im = ax.imshow(img, #Colormapped or RGB arrays
      cmap= 'gist_earth', 
      interpolation= 'nearest',
>>> axes2[0].pcolor(data2) #Pseudocolor plot of 2D array
>>> axes2[0].pcolormesh(data) #Pseudocolor plot of 2D array
>>> CS = plt.contour(Y,X,U) #Plot contours
>>> axes2[2].contourf(data1) #Plot filled contours
>>> axes2[2]= ax.clabel(CS) #Label a contour plot

Vector Fields 

>>> axes[0,1].arrow(0,0,0.5,0.5) #Add an arrow to the axes
>>> axes[1,1].quiver(y,z) #Plot a 2D field of arrows
>>> axes[0,1].streamplot(X,Y,U,V) #Plot a 2D field of arrows

Data Distributions 

>>> ax1.hist(y) #Plot a histogram
>>> ax3.boxplot(y) #Make a box and whisker plot
>>> ax3.violinplot(z)  #Make a violin plot

Plot Anatomy & Workflow 

Plot Anatomy 




The basic steps to creating plots with matplotlib are:

1 Prepare Data
2 Create Plot
3 Plot
4 Customized Plot
5 Save Plot
6 Show Plot

>>> import matplotlib.pyplot as plt
>>> x = [1,2,3,4]  #Step 1
>>> y = [10,20,25,30] 
>>> fig = plt.figure() #Step 2
>>> ax = fig.add_subplot(111) #Step 3
>>> ax.plot(x, y, color= 'lightblue', linewidth=3)  #Step 3, 4
>>> ax.scatter([2,4,6],
          color= 'darkgreen',
          marker= '^' )
>>> ax.set_xlim(1, 6.5)
>>> plt.savefig('foo.png' ) #Step 5
>>> #Step 6

Close and Clear 

>>> plt.cla()  #Clear an axis
>>> plt.clf(). #Clear the entire figure
>>> plt.close(). #Close a window

Plotting Customize Plot 

Colors, Color Bars & Color Maps 

>>> plt.plot(x, x, x, x**2, x, x** 3)
>>> ax.plot(x, y, alpha = 0.4)
>>> ax.plot(x, y, c= 'k')
>>> fig.colorbar(im, orientation= 'horizontal')
>>> im = ax.imshow(img,
            cmap= 'seismic' )


>>> fig, ax = plt.subplots()
>>> ax.scatter(x,y,marker= ".")
>>> ax.plot(x,y,marker= "o")


>>> plt.plot(x,y,linewidth=4.0)
>>> plt.plot(x,y,ls= 'solid') 
>>> plt.plot(x,y,ls= '--') 
>>> plt.plot(x,y,'--' ,x**2,y**2,'-.' ) 
>>> plt.setp(lines,color= 'r',linewidth=4.0)

Text & Annotations 

>>> ax.text(1,
           'Example Graph', 
            style= 'italic' )
>>> ax.annotate("Sine", 
xy=(8, 0),
xycoords= 'data', 
xytext=(10.5, 0),
textcoords= 'data', 
arrowprops=dict(arrowstyle= "->", 


>>> plt.title(r '$sigma_i=15$', fontsize=20)

Limits, Legends and Layouts 

Limits & Autoscaling 

>>> ax.margins(x=0.0,y=0.1) #Add padding to a plot
>>> ax.axis('equal')  #Set the aspect ratio of the plot to 1
>>> ax.set(xlim=[0,10.5],ylim=[-1.5,1.5])  #Set limits for x-and y-axis
>>> ax.set_xlim(0,10.5) #Set limits for x-axis


>>> ax.set(title= 'An Example Axes',  #Set a title and x-and y-axis labels
            ylabel= 'Y-Axis', 
            xlabel= 'X-Axis')
>>> ax.legend(loc= 'best')  #No overlapping plot elements


>>> ax.xaxis.set(ticks=range(1,5),  #Manually set x-ticks
             ticklabels=[3,100, 12,"foo" ])
>>> ax.tick_params(axis= 'y', #Make y-ticks longer and go in and out
             direction= 'inout', 

Subplot Spacing 

>>> fig3.subplots_adjust(wspace=0.5,   #Adjust the spacing between subplots
>>> fig.tight_layout() #Fit subplot(s) in to the figure area

Axis Spines 

>>> ax1.spines[ 'top'].set_visible(False) #Make the top axis line for a plot invisible
>>> ax1.spines['bottom' ].set_position(( 'outward',10))  #Move the bottom axis line outward

Have this Cheat Sheet at your fingertips

Original article source at

#matplotlib #cheatsheet #python

Eric  Bukenya

Eric Bukenya


.NET Conf 2020 Demos & Sessions for .NET 5 + Virtual Events!

This year’s .NET Conf was the largest one yet, with over 80 live sessions across three days that were co-organized and presented by the .NET community and Microsoft. On top of all of that, it also marked the release of .NET 5.0  that brings a full set of new capabilities, performance gains, and new languages features for developers to create amazing apps. If you missed this year’s .NET Conf live stream, don’t worry because we have you covered! core #c# conf foundation #community #demos

Aisu  Joesph

Aisu Joesph


.NET News Roundup: .NET 6, MAUI, EF Core 6, Visual Studio 2022

It’s been a busy week for the .NET community with the release of new previews for .NET 6 and its related frameworks (including MAUI), along with the first preview of Visual Studio 2022, new Azure SDK libraries, and more. InfoQ examined these and a number of smaller stories in the .NET ecosystem from the week of June 14th, 2021.

This week’s highlight was the release of new previews for .NET 6 and its related frameworks. .NET 6 Preview 5 includes improvements to a new feature named SDK workloads, which - according to Richard Lander, program manager for the .NET team at Microsoft - is the foundation of the .NET unification vision. The new feature allows developers to add support for new application types (such as mobile and WebAssembly) without increasing the size of the SDK. The improvements to the new feature are the inclusion of two new verbs - list and update - providing a sense of the expected final experience with the general availability release in November. Other features in .NET 6 Preview 5 include NuGet package validationmore Roslyn analyzers, improvements in the Microsoft.Extensions APIs (focused on hosting and dependency injection), WebSocket compression, and much more. Also according to Lander, “.NET 6 Preview 5 is perhaps the biggest preview yet in terms of breadth and quantity of features.” A comprehensive list of all features included in the new preview can be found in the official release post.

The ASP.NET Core framework also received significant improvements in .NET 6 Preview 5. One of the most important features of this release is the reduced Blazor WebAssembly download size with runtime relinking. Now developers can use the .NET WebAssembly tools (the same tools also used for .NET WebAssembly AOT compilation) to relink the runtime and remove unnecessary logic, dramatically reducing the size of the runtime. According to Microsoft, the size reduction is particularly relevant when using invariant globalization mode. Other features in the new release include .NET Hot Reload updates for dotnet watch, faster get and set for HTTP headers, and ASP.NET Core SPA templates updated to Angular 11 and React 17.

#azure maui #visual studio 2019 6 #visual studio 2022 #devops #news

Hire Dedicated ASP.NET Developers | ASP.NET Web Development Company

A universally accepted and the most popular framework that can be used for a small or big websites or Web application development projects is the ASP.NET. This framework is majorly used to produce an interactive and data driven web applications.

Are you looking to use an ASP.NET framework for your development needs?

WebClues Infotech offers a dedicated ASP.NET developers where a business can hire a dedicated ASP.NET developer that matches their project requirement. WebClues Infotech also has a flexible pricing structure that suits most project or business requirements.

Want to hire a dedicated ASP.NET developers?

Share your requirements here

Book Free Interview with ASP.NET developer:

#hire dedicated developers #hire developers #hire .net developers #full-stack .net developers india #dedicated .net programmers india #hire developers or programmers