Turwaith
Turwaith

Reputation: 67

C# WPF: Complex Shape objects on a Canvas? MVVM

This is more of a "Is it possible (with a reasonable amount of time and work)" than a "how exactly is it possible" question. I'm getting into WPF at the moment and am interested in graphical applications in an MVVM approach. In the meaning of an ms-paint like application. Now I see that and how I can draw e.g. a ractangle on a canvas, store those rectangles in a list etc. But I am wondering if I can do that more advanced. For example extend the rectangle so I can give it more infos (I can't extend the rectangle itself since it's a sealed class), have existing shapes on the canvas able to drag them around, make the shapes complex (e.g. I double click one to open a new Window that represents the "inside" of that shape) etc.

Is such an application possible with a reasonable amount of work and time in WPF or would I rather use some different library/framework for this?

Upvotes: 1

Views: 1048

Answers (1)

Muhammad Sulaiman
Muhammad Sulaiman

Reputation: 2605

Yes, It is possible, Actually, you are listing CAD specifications, In fact, I work on this type of technology, so I'll suggest you some resources to have a clue..

  1. Take a look at this project(WPF, 2D)

enter image description here

  1. And this one(WPF, 3D)

enter image description here

  1. And this one(WPF, 2D)

enter image description here

  1. The previous projects are WPF-based, also, you might host a WinForm control in your WPF app, take a look at this one(WinForms, 2D)

enter image description here


If you change the specification a bit and say: "I don't want to edit the drawings on the canvas", then you could go with this option: convert your shapes to PathFigureCollection and EllipseGeometry objects, then construct Paths from these objects and add the Paths to the Canvas, this is a pure WPF approach. Indeed, you can add traditinal controls like TextBlocks as children to your Canvas, I have done such one like this..

enter image description here

Hope it helps.

Upvotes: 4

Related Questions