简体   繁体   中英

Drawing a shape without XAML

Hi I am trying to draw a simple shape of rectangle in a middle of my screen. Unfortunately all the tutorials I found online tells me how to do it in XAML. The one tutorial I found tells me how to draw rectangle in a windows form

System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(50, 100, 150, 150);

graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle);
graphics.DrawRectangle(System.Drawing.Pens.Red, rectangle);

however this does not work inside Universal app. Is there an analog of something like this for Universal app? Thank you very much

Short answer: No, not really.

In Windows Universal Apps you have 3 main choices to draw something on the screen:

1- You can use XAML components as you have seen already, you can create such components programmatically as well and create animations with them .

2- You can create an HTML/Javascript-based application

3- You can use a XAML control as a raw canvas and draw graphics on it using DirectX/DirectWrite , but you may need to use C++ for doing the actual drawing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM