2

I am new to GUI development and I am aware converting between Winforms and WPF has previously been addressed. However, as a newbee, I am still unclear as to the best way forward and I would be very grateful for you help.

I basically have two SDK sample codes I am trying to combine. One sample code is written in winforms and the other in WPF. As I envisage my end-product to include animation, I believe I should translate the winforms code to WPF (pls correct me if you disagree). However it a complex and lengthy code and as I am relatively more comfortable with winforms, I wondered whether I should consider WPF to winforms translation and use an Open GL control. What is the most efficient way forward? From the winforms sample code, I need data from a DataGrid and from the WPF, I need access to a 512x512 live image currently displayed on a WindowsFormsHost.

Thank you all very much in advance for your help!!

FunkDoc
  • 21
  • 1
  • 2
  • 1
    It is very hard to give advice without knowing your experience, the sample code you are talking about, or what you are trying to do. – Dour High Arch Jun 12 '13 at 17:19
  • The code I would like to convert from Winforms to WPF is from [link] (http://www.naturalpoint.com/optitrack/downloads/developer-tools.html) in the Samples/winformsSample folder. I have little experience of C# but thanks to this site and the WPF in 24hrs book, I am learning fast. I am trying to combine the data from motion tracking cameras (x, y, and Z positional data of markers, displayed in the DataGridView the sample code) with live image data to build a 3D volume data. Thanks for your help! @DourHighArch – FunkDoc Jun 14 '13 at 09:53
  • If you don't need a animation visual effect or any eye-candy UI, i suggest you go for Winforms. It simple and faster development time.Otherwise, if you have a teams, you have to ensure your team member know WPF. – Cheung Oct 23 '13 at 04:05

2 Answers2

6

I am new to GUI development

I must warn you that WPF has a really steep learning curve. I would go as far as to say that it's not suitable for the unexperienced.

converting between Winforms and WPF

The problem is not the code in itself. The problem is the mentality with which it is written:

  • All the "traditional" winforms code behind is absolutely unneeded in WPF.

  • In WPF, there's DataBinding (well, actually winforms has something called databinding but that's laughable compared to WPF (as much as anything else in winforms). This completely removes the need to create OR manipulate ANY UI Element in procedural code. Everything is defined in XAML and then DataBound to the relevant Models and ViewModels. That's why there's a huge difference in the mentality required for this.

    • In winforms, the UI stores information about it's state. In order to read/retrieve/modify this information, you have to access these UI elements in code.
    • In WPF, the ViewModel and the Model (simple classes that you create to store your data and that are not tied to the UI at all) store this state information. In order to read/retrieve/modify this information, you do NOT access the UI elements in code.

The WPF Visual Tree is very much more complex than the winforms X,Y approach. Therefore getting a hold of some UI element deeply buried within, let's say a DataTemplate used for an ItemsControl which is inside a DataTemplate used as the CellTemplate of a DataGrid is something that you really don't want to get into. Believe me.

I suggest that you read @Rachel's Excellent Explanation and linked blog posts to better understand what's required to transition from the clumsy, boring, too-much-code-for-everything winforms world into the beautiful, customizable, scalable, pleasant world of XAML and DataBinding (applicable to all XAML-Based technologies WPF, WinRT, Silverlight, Windows Phone, etc).

As I envisage my end-product to include animation

If you are about to start (or starting) a new product, forget winforms. It's dead. It doesn't support anything aside from the default ugly stuff. It cannot be customized / animated / beautified without resorting to a lot of horrible hacks.

Everyone will tell you that winforms is only to maintain legacy applications, but no longer an option for anyone who starts any serious project.

However it a complex and lengthy code and as I am relatively more comfortable with winforms

Once you learn MVVM, You will quickly realize that WPF requires 10% of the code required to do anything in winforms. Your complex and lengthy code (probably code-behind) will be reduced to Simple, Simple properties and INotifyPropertyChanged. That's how you code in WPF.

Community
  • 1
  • 1
Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154
  • Downvoter, care to comment? the fact that you don't like my answer doesn't make it less true. winforms is a crappy dinosaur. – Federico Berasategui Jun 12 '13 at 15:36
  • Thank you @HighCore ! I am sold, WPF is definitely the way to go. I appreciate the learning curve is steep and its going to be painful, but I think it will be worth it. Its a shame I can not vote yet. – FunkDoc Jun 14 '13 at 09:57
  • @Eskinder, you thank people by clicking the check mark at the upper left of their answer. You'll even get a shiny new badge in your profile. – Dour High Arch Jun 14 '13 at 16:05
  • @HighCore I upvoted you, but I disagree with your characterisation of WinForms as "dead. It doesn't support anything [...] default ugly stuff. It cannot be customized / animated / beautified [...]". WinForms has its place especially for RAD tasks where direct UI manipulation is less work than setting up MVVM. Also, a criticism of WPF: XAML-based data-binding is untyped and often (in my experience) results in a lot of runtime errors until it's working. I suppose I'd love WPF more if the tooling let you use WPF without XAML. – Dai Apr 29 '15 at 23:32
2

The time you will save with the separation that WPF allows is worth the effort to switch from winforms. I cannot think of a reason why you should move backwards (not saying there isn't a reason, though.

You can even do this in pieces with the windows forms wpf wrapper. Then, once you have everything converted, you can just remove any wrappers and it will be a full wpf application

SO question about advantages of WPF to winforms

Community
  • 1
  • 1
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180