Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI...
I'm working with VC# in windows forms mode, and I have to give to my project some beauty. I had listened for WPF this can help me to transform my project to an other more inportance in the style and form.

How can I do to transform this project?
Posted
Updated 18-Apr-11 10:45am
v2

If your Winforms app was written with strict MVP enforcement, you may be able to reuse your model and view classes to an extent. WPF's equivalent would be the MVVM model.

An alternateive you can do is to partially port over from Winforms to WPF, and do the full port in multiple steps. Interop works both ways between the two - WPF can host Winforms controls and Winforms can host WPF controls. So for a few iterations you will have an app that's a hybrid of the two. Once you've ported everything over, you can then remove the Winforms assemblies.

That would be a sensible and practical approach, specially for a large application.
 
Share this answer
 
Comments
Espen Harlinn 18-Apr-11 18:19pm    
Good suggestion, my 5
Nish Nishant 18-Apr-11 18:23pm    
Thanks Espen!
Sergey Alexandrovich Kryukov 19-Apr-11 0:44am    
A wise idea, my 5, the initial assumption does not look very realistic though :-)
--SA
BobJanova 19-Apr-11 6:17am    
Hehe, indeed, very few WinForms apps are written that way.
Sergey Alexandrovich Kryukov 19-Apr-11 13:12pm    
The key is isolation of UI from both universal and application-specific part of codes; and this is mostly because UI is very fragile, ever changing (replacing) and non-portable. Perhaps most developers are to weak to resolve this problem. These design patterns are built around this need, in fact.
--SA
You need to convert the entire application - BY HAND - to WPF. There is no conversion utility. WinForms and WPF are so different that you even have to consider a different threading model. And effective databinding almost requires that you modify all of your collections and the objects they represent.

It's not a trivial task, and if you're just trying to "add beauty", my suggestion is that you resist the urge for such an unimportant and non-functional reason.
 
Share this answer
 
v2
Comments
guendouz bachir 18-Apr-11 18:42pm    
give me an example of lesson from what you have saying thx
Sergey Alexandrovich Kryukov 19-Apr-11 0:43am    
True, my 5. Well, there are many similar ideas and almost one-to-one classes, but it's still re-writing...

By the way, why everyone so afraid of re-writing? This is one of the ways to create a mature project. Working time? Nonsense! Ever-lasting "fixed" can take ten times more time, but everyone falls in the illusion of "reuse".

--SA
BobJanova 19-Apr-11 6:18am    
Indeed. This is another question that should be answered with 'Why do you want to do that?'. WinForms is not ugly, it fits the user's expectations for how an app should behave (rather better than WPF in general) and moving an app to WPF 'just because' is a big waste of time (unless it is a learning exercise).
we have used a utility to do.
It can convert your VB.net forms to WPF.
 
Share this answer
 
Comments
Francisco T. Chavez 26-Apr-13 18:54pm    
I can't help but noticed that you didn't say anything about the end result.
HM India 27-Apr-13 4:09am    
Its worked fantastic.
Francisco T. Chavez 29-Apr-13 14:06pm    
In that case, what program did you guys use?
I agree with John Simmons in that you will most likely have to convert most of the application by hand. And, if you're doing this just to make it pretty, then maybe you shouldn't bother.

That being said, if you still want to go through with this, there are a few things you need to know:

  • System.Collection.ObjectModel.ObseverableCollection<T>(s) are your friends.
  • The App class is the starting point, don't replace this starting because you want the main method back.
  • The XAML page for the App class is where you store you application wide resources. Sure, you can define these resources in a dictionary file and instantiate that file in each window/control, but then you'll end up with multiple copies of the same items all over the place (this is what you'll end up doing if you replace the App class as your starting point).
  • The App class has events you can use to insert code that need to run before the MainWindow is opened and after you close it. Remember this is event based so having a using(var x = ...){ } statement will NOT span the entire application. This code will need to be split apart.
  • Take a good look at the MVVM pattern. There's some stuff in there that I thought was really stupid. Then one day, I was porting sections of a WinForms app into a WPF app, and I thought, "If I had done <blank> from the start, this would be a lot easier." Then I remembered that MVVM does <blank> and it no long seemed like a stupid thing to do.
  • DependencyObjects can only have one parent in the VisualTree (it's possible to try to give them two parents by making them into a resource).
  • The DataContext is not part of the VisualTree path, it's just the starting point for your binding objects.
  • A template will build every item in the template for the object you apply the template to. If the template contains a reference to another resource, it will build a reference to that resource. So that resource better NOT be something that can only show up in one spot of the VisualTree.
  • Find a snippet(s) for implementing System.ComponentModel.INotifityPropertyChanged, it will save you a lot of time, effort, and debugging.
  • The WPF way isn't always the best way, somethings are just a lot easier to do in code then in bindings (real time propagation of RadioButton selection). I took me months of always trying to do it the WPF before I started to get a good sense of when I should just do it in code.
 
Share this answer
 
v2

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