Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert code xaml below to C#(GDI+). PLease> Thanks

<canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:name="Document" width="173.151" height="144.664" clip="F1 M 0,0L 173.151,0L 173.151,144.664L 0,144.664L 0,0">
<canvas x:name="Pneumatic_brake1" width="799.697" height="599.608" canvas.left="0" canvas.top="0">
<rectangle x:name="Rectangle" width="39.8247" height="23.5607" canvas.left="133.326" canvas.top="60.5517" stretch="Fill" fill="#F3BFBFBF">
<rectangle x:name="Rectangle_0" width="39.8247" height="20.2032" canvas.left="133.326" canvas.top="62.2304" stretch="Fill" fill="#F3CACACA">
<rectangle x:name="Rectangle_1" width="39.8247" height="16.8456" canvas.left="133.326" canvas.top="63.9092" stretch="Fill" fill="#F3D5D5D5">
<rectangle x:name="Rectangle_2" width="39.8247" height="13.4881" canvas.left="133.326" canvas.top="65.588" stretch="Fill" fill="#F3DFDFDF">
<rectangle x:name="Rectangle_3" width="39.8247" height="10.1306" canvas.left="133.326" canvas.top="67.2668" stretch="Fill" fill="#F3E9E9E9">
<rectangle x:name="Rectangle_4" width="39.8247" height="6.77301" canvas.left="133.326" canvas.top="68.9455" stretch="Fill" fill="#F3F5F5F5">
<rectangle x:name="Rectangle_5" width="39.8247" height="3.35754" canvas.left="133.326" canvas.top="70.6243" stretch="Fill" fill="#F3FFFFFF">
<path x:name="Path" width="39.8247" height="23.5607" canvas.left="133.326" canvas.top="60.5517" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 133.326,60.5517L 173.151,60.5517L 173.151,84.1124L 133.326,84.1124L 133.326,60.5517">
<path x:name="Path_6" width="133.326" height="144.664" canvas.left="0" canvas.top="-3.05176e-005" stretch="Fill" fill="#F3838383" data="M 0,-3.05176e-005L 72.0885,3.76276L 72.0885,10.9409L 122.822,10.9409L 122.822,3.76276L 129.979,3.76276L 129.979,43.3008L 133.326,43.3008L 133.326,101.363L 129.979,101.363L 129.979,140.843L 122.822,140.843L 122.822,133.723L 72.0885,133.723L 72.0885,140.843L 0,144.664L 0,-3.05176e-005 Z ">
<path x:name="Path_7" width="133.73" height="132.855" canvas.left="0" canvas.top="5.90463" stretch="Fill" fill="#F3929292" data="M 0,5.90463L 72.0885,9.26218L 72.0885,15.9773L 122.822,15.9773L 122.822,9.26218L 129.979,9.26218L 129.979,45.8479L 133.73,45.8479L 133.73,98.8162L 129.979,98.8162L 129.979,135.402L 122.822,135.402L 122.822,128.687L 72.0885,128.687L 72.0885,135.402L 0,138.759L 0,5.90463 Z ">
<path x:name="Path_8" width="133.73" height="121.103" canvas.left="0" canvas.top="11.7514" stretch="Fill" fill="#F39E9E9E" data="M 0,11.7514L 72.0885,14.7037L 72.0885,21.0136L 122.822,21.0136L 122.822,14.7037L 129.979,14.7037L 129.979,47.9319L 133.73,47.9319L 133.73,96.2691L 129.979,96.2691L 129.979,129.497L 122.822,129.497L 122.822,123.65L 72.0885,123.65L 72.0885,129.497L 0,132.855L 0,11.7514 Z ">
<path x:name="Path_9" width="133.73" height="109.352" canvas.left="0" canvas.top="17.6561" stretch="Fill" fill="#F3AEAEAE" data="M 0,17.6561L 72.0885,20.6084L 72.0885,26.0499L 122.822,26.0499L 122.822,20.6084L 129.979,20.6084L 129.979,50.479L 133.73,50.479L 133.73,94.1851L 129.979,94.1851L 129.979,124.056L 122.822,124.056L 122.822,118.556L 72.0885,118.556L 72.0885,124.056L 0,127.008L 0,17.6561 Z ">
<path x:name="Path_10" width="133.73" height="97.5426" canvas.left="0" canvas.top="23.5607" stretch="Fill" fill="#F3BDBDBD" data="M 0,23.5607L 72.0885,26.0499L 72.0885,30.6811L 122.822,30.6811L 122.822,26.0499L 129.979,26.0499L 129.979,52.9682L 133.73,52.9682L 133.73,91.6958L 129.979,91.6958L 129.979,118.556L 122.822,118.556L 122.822,113.52L 72.0885,113.52L 72.0885,118.556L 0,121.103L 0,23.5607 Z ">
<path x:name="Path_11" width="133.73" height="85.7912" canvas.left="0" canvas.top="29.4075" stretch="Fill" fill="#F3C2C2C2" data="M 0,29.4075L 72.0885,31.5494L 72.0885,35.7174L 122.822,35.7174L 122.822,31.5494L 129.979,31.5494L 129.979,55.1101L 133.73,55.1101L 133.73,89.554L 129.979,89.554L 129.979,112.71L 122.822,112.71L 122.822,108.484L 72.0885,108.484L 72.0885,112.71L 0,115.199L 0,29.4075 Z ">
<path x:name="Path_12" width="133.73" height="73.5767" canvas.left="0" canvas.top="35.3122" stretch="Fill" fill="#F3C7C7C7" data="M 0,35.3122L 72.0885,37.3961L 72.0885,40.8116L 122.822,40.8116L 122.822,37.3961L 129.979,37.3961L 129.979,57.5993L 133.73,57.5993L 133.73,87.0647L 129.979,87.0647L 129.979,107.21L 122.822,107.21L 122.822,103.447L 72.0885,103.447L 72.0885,107.21L 0,108.889L 0,35.3122 Z ">
<path x:name="Path_13" width="133.73" height="61.8252" canvas.left="0" canvas.top="41.2168" stretch="Fill" fill="#F3CBCBCB" data="M 0,41.2168L 72.0885,42.8956L 72.0885,45.8479L 122.822,45.8479L 122.822,42.8956L 129.979,42.8956L 129.979,59.6833L 133.73,59.6833L 133.73,84.5176L 129.979,84.5176L 129.979,101.768L 122.822,101.768L 122.822,98.4109L 72.0885,98.4109L 72.0885,101.768L 0,103.042L 0,41.2168 Z ">
<path x:name="Path_14" width="133.73" height="50.0159" canvas.left="0" canvas.top="47.1215" stretch="Fill" fill="#F3D0D0D0" data="M 0,47.1215L 72.0885,48.3371L 72.0885,50.8842L 122.822,50.8842L 122.822,48.3371L 129.979,48.3371L 129.979,62.2304L 133.73,62.2304L 133.73,82.4336L 129.979,82.4336L 129.979,95.8638L 122.822,95.8638L 122.822,93.3746L 72.0885,93.3746L 72.0885,95.8638L 0,97.1374L 0,47.1215 Z ">
<path x:name="Path_15" width="133.73" height="37.8014" canvas.left="0" canvas.top="53.4313" stretch="Fill" fill="#F3D5D5D5" data="M 0,53.4313L 72.0885,54.2418L 72.0885,55.9206L 122.822,55.9206L 122.822,54.2418L 129.979,54.2418L 129.979,64.7776L 133.73,64.7776L 133.73,79.8865L 129.979,79.8865L 129.979,90.4223L 122.822,90.4223L 122.822,88.2804L 72.0885,88.2804L 72.0885,90.4223L 0,91.2327L 0,53.4313 Z ">
<path x:name="Path_16" width="133.73" height="26.1078" canvas.left="0" canvas.top="59.2781" stretch="Fill" fill="#F3D9D9D9" data="M 0,59.2781L 72.0885,59.6833L 72.0885,60.9569L 122.822,60.9569L 122.822,59.6833L 129.979,59.6833L 129.979,66.8615L 133.73,66.8615L 133.73,77.3973L 129.979,77.3973L 129.979,84.9229L 122.822,84.9229L 122.822,83.244L 72.0885,83.244L 72.0885,84.9229L 0,85.386L 0,59.2781 Z ">
<path x:name="Path_17" width="133.326" height="14.2985" canvas.left="0" canvas.top="65.1828" stretch="Fill" fill="#F3EAEAEA" data="M 0,65.1828L 72.0885,65.588L 72.0885,65.9932L 122.822,65.9932L 122.822,65.588L 129.979,65.588L 129.979,69.4087L 133.326,69.4087L 133.326,75.2554L 129.979,75.2554L 129.979,79.0761L 122.822,79.0761L 122.822,78.6129L 72.0885,78.6129L 72.0885,79.0761L 0,79.4813L 0,65.1828 Z ">
<path x:name="Path_18" width="133.326" height="144.664" canvas.left="0" canvas.top="-3.05176e-005" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 0,-3.05176e-005L 72.0885,3.76276L 72.0885,10.9409L 122.822,10.9409L 122.822,3.76276L 129.979,3.76276L 129.979,43.3008L 133.326,43.3008L 133.326,101.363L 129.979,101.363L 129.979,140.843L 122.822,140.843L 122.822,133.723L 72.0885,133.723L 72.0885,140.843L 0,144.664L 0,-3.05176e-005">
<rectangle x:name="Rectangle_19" width="50.3292" height="10.941" canvas.left="14.6601" canvas.top="66.8615" stretch="Fill" fill="#F3A9A9A9">
<rectangle x:name="Rectangle_20" width="50.3292" height="10.5358" canvas.left="14.6601" canvas.top="105.531" stretch="Fill" fill="#F35C5C5C">
<rectangle x:name="Rectangle_21" width="50.3292" height="10.941" canvas.left="14.6601" canvas.top="28.1918" stretch="Fill" fill="#F35C5C5C">
<rectangle x:name="Rectangle_22" width="50.3292" height="10.5358" canvas.left="14.6601" canvas.top="124.866" stretch="Fill" fill="#F3373737">
<rectangle x:name="Rectangle_23" width="50.3292" height="10.4779" canvas.left="14.6601" canvas.top="9.26218" stretch="Fill" fill="#F3373737">
<rectangle x:name="Rectangle_24" width="50.3292" height="10.941" canvas.left="14.6601" canvas.top="47.5267" stretch="Fill" fill="#F3838383">
<rectangle x:name="Rectangle_25" width="50.3292" height="10.941" canvas.left="14.6601" canvas.top="86.1964" stretch="Fill" fill="#F3838383">
<rectangle x:name="Rectangle_26" width="50.7332" height="21.824" canvas.left="72.0885" canvas.top="61.42" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF405473" fill="#F3EAEAEA">
<path x:name="Line" width="0" height="122.782" canvas.left="122.822" canvas.top="10.9409" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 122.822,133.723L 122.822,10.9409">
<path x:name="Line_27" width="0" height="58.0624" canvas.left="129.979" canvas.top="43.3008" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 129.979,101.363L 129.979,43.3008">
<path x:name="Line_28" width="0" height="122.782" canvas.left="72.0885" canvas.top="10.9409" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 72.0885,133.723L 72.0885,10.9409">
<path x:name="Line_29" width="0" height="137.081" canvas.left="64.9893" canvas.top="3.76276" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 64.9893,140.843L 64.9893,3.76276">
<path x:name="Line_30" width="0" height="142.927" canvas.left="14.6601" canvas.top="0.868317" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 14.6601,143.796L 14.6601,0.868317">
<path x:name="Line_31" width="0" height="142.927" canvas.left="7.09918" canvas.top="0.868317" stretch="Fill" strokethickness="1" strokemiterlimit="2.75" stroke="#FF000000" data="M 7.09918,143.796L 7.09918,0.868317">



What I have tried:

How to convert code xaml below to C#(GDI+). PLease> Thanks
Posted
Updated 9-Apr-19 9:09am
Comments
[no name] 10-Apr-19 11:48am    
1

All this does is create a surface to draw on and starts drawing a bunch of stuff on it.

You're going to have to convert this code by hand if you want to do it in Windows Forms. It's going to take a control to draw on, like a Panel, and a ton of drawing commands, like Graphics.DrawRectangle and Graphics.DrawLine.

There is no tool that's going to do this for you.
 
Share this answer
 
Comments
Le Khai Hoan 9-Apr-19 13:33pm    
Could you help me?
Dave Kreskowiak 9-Apr-19 14:03pm    
I've shown you the documentation on the elements you posted. It's up to you to convert the code. I don't have to the time to do your work for you and you're not going to do mine for me, so...
Le Khai Hoan 9-Apr-19 14:06pm    
Because Winform not suport library Window.UI as WPF
Dave Kreskowiak 9-Apr-19 14:15pm    
Yeah, because Windows Forms is not WPF. You cannot use the XAML you posted in a Windows Forms app.

You have to understand what that XAML is doing (see the documentation links) and write Windows Form code to do approximately the same thing. And that requires you to know how to do custom drawing in Windows Forms. If you don't know how to draw on a control surface in Windows Forms, you're not going to be able to do this at all until you learn that too!
[no name] 10-Apr-19 11:48am    
1
You got "rectangles" and "path geometry" (a bunch of lines). Use the equivalent in GDI+.

Pens, Lines, and Rectangles in GDI+ | Microsoft Docs[^]
 
Share this answer
 
Comments
Le Khai Hoan 9-Apr-19 15:12pm    
Because path of xaml have a contain DATA. I dont know convert it?
Dave Kreskowiak 9-Apr-19 18:52pm    
So what do you think that data is? It's really easy to figure out if you read the documentation on that Path element. It's X,Y coordinate data for each point in a set of lines. This is not hard to figure out.
Le Khai Hoan 9-Apr-19 19:06pm    
Do you have examble about this?
[no name] 10-Apr-19 11:48am    
1
T dont have a tool ! And i dont know line commands of xaml to c#.
 
Share this answer
 
Comments
Dave Kreskowiak 9-Apr-19 13:36pm    
First, you posted this as a SOLUTION to your own question, not a response to me.

Second, nobody has a tool! It doens't exist!

if you don't know something, you better go learn it. The documentation on the rectangle element is here[^]. Path is here[^]. Canvas is here[^].
Le Khai Hoan 9-Apr-19 13:42pm    
Ok Thanks u !!
Le Khai Hoan 9-Apr-19 14:00pm    
I use to winform C#. Dont use UWP or WPF

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900