7 Replies - 517 Views - Last Post: 20 April 2020 - 10:56 AM Rate Topic: -----

#1 ScottinTexas   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 333
  • Joined: 13-March 12

Replacing a Windows Form with an XAML Window at start up

Posted 16 April 2020 - 07:39 AM

So I have a new task to "support", not rewrite, a windows forms program that has several things wrong with the main window.I would like to replace the main window but I want to use a XAML form. I added a XAML Window to the project and put a couple controls on it, but I don't know if it can replace the start up form or how to do it. I looked in the project properties the start up form drop down only lists the frmMain. Can I do what I want? If so, how?

Thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: Replacing a Windows Form with an XAML Window at start up

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7445
  • View blog
  • Posts: 25,082
  • Joined: 05-May 12

Re: Replacing a Windows Form with an XAML Window at start up

Posted 16 April 2020 - 08:33 AM

See: Add a WPF control to a Windows Form

So just create essentially a frame of a WinForms form, and then in the form host a WPF control that has the WPF UI that you want.
Was This Post Helpful? 1
  • +
  • -

#3 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3150
  • View blog
  • Posts: 11,954
  • Joined: 03-December 12

Re: Replacing a Windows Form with an XAML Window at start up

Posted 16 April 2020 - 09:16 AM

View PostScottinTexas, on 16 April 2020 - 09:39 AM, said:

So I have a new task to "support", not rewrite, a windows forms program
...
Can I do what I want?


Wouldn't that entail rewriting it? As to whether you can do it, that depends on your permissions. If I assign someone to support a project, I expect them to support it, not to redo it how they think it should be done, but that's me.
Was This Post Helpful? 0
  • +
  • -

#4 ScottinTexas   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 333
  • Joined: 13-March 12

Re: Replacing a Windows Form with an XAML Window at start up

Posted 20 April 2020 - 08:20 AM

View Postastonecipher, on 16 April 2020 - 11:16 AM, said:

Wouldn't that entail rewriting it? As to whether you can do it, that depends on your permissions. If I assign someone to support a project, I expect them to support it, not to redo it how they think it should be done, but that's me.


Rewrite means scrap the entire windows forms mess and start from scratch. Replacing the UI is not the same. I want to replace it, but I don't know how to do that with a Windows Forms program. I haven't used a Windows form since VB6 I think. When I got back into programming it was XAML and WPF. So my idea was to replace the Winforms window with a working XAML form that had data binding and all of the simplicity to which I am accustomed. I don't get assigned things like you describe. There's more than I can go into, but if I wanted to replace the main window, I could, and not change what the program is doing.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15781
  • View blog
  • Posts: 63,250
  • Joined: 12-June 08

Re: Replacing a Windows Form with an XAML Window at start up

Posted 20 April 2020 - 08:27 AM

Honestly I wouldn't try and mush in a XAML form into a Winforms project. Sure it's what you are used to, but in my experience that sort of straddling tech almost always leads to massive headaches down the road. Be it for you later, competing tech upgrades, or any one else doing maintenance.

If you don't have a the green light for a rewrite then just correct the form's issues and move on.
Was This Post Helpful? 1
  • +
  • -

#6 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3150
  • View blog
  • Posts: 11,954
  • Joined: 03-December 12

Re: Replacing a Windows Form with an XAML Window at start up

Posted 20 April 2020 - 08:40 AM

View PostScottinTexas, on 20 April 2020 - 10:20 AM, said:

There's more than I can go into, but if I wanted to replace the main window, I could, and not change what the program is doing.


That just means the layers are siloed correctly. And once again, that means rewriting it. Rewriting doesn't mean all, it means any portion thereof. Splitting tech just because it is something you are more comfortable with also makes it harder on the person that isn't more comfortable with what you chose, and is outside of the norm if everything else uses the same technology.

This isn't a decision that is up to you, unless you were explicitly given carte blanche. It is a decision from the people that are actually driving the technology, because it ultimately falls on them when something like this goes badly (regardless of whether you think it will all be hunky dory or not). Meaning, everyone else knows how to do WinForms, you decide to do it how you want. You get a better offer and leave next month and it is now someone else's problem, but they don't know how to fix it because you didn't follow the pattern everyone else uses.
Was This Post Helpful? 1
  • +
  • -

#7 andrewsw   User is online

  • palpable absurdity
  • member icon

Reputation: 6905
  • View blog
  • Posts: 28,565
  • Joined: 12-December 12

Re: Replacing a Windows Form with an XAML Window at start up

Posted 20 April 2020 - 09:51 AM

I agree with the two gentlemen above.

You may not have worked with WinForms for a long time but you aren't starting from scratch. You have the remainder of the application to offer some guidance, and to follow its existing patterns. Admittedly, the application may be poorly written and designed, which you'll probably recognise as you progress. Nonetheless, the immediate concern is to fix the UI issues with the main form. You can use some good code and design but shouldn't take it too far away (at this stage) from the current code base.
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7445
  • View blog
  • Posts: 25,082
  • Joined: 05-May 12

Re: Replacing a Windows Form with an XAML Window at start up

Posted 20 April 2020 - 10:56 AM

Also I believe that AndrewSW has (or was working on) a MV* tutorial for WinForms. I though that he was doing MVP, but I may have just killed too many brain cells when I had a crazy 6 week long cough starting back in December.

So basically what I am saying is that you can still implement the separation of view, model, and business logic. Nothing about using WinForms compels you to go back to the dark ages of mixing together these three major components. WinForms also has its own version of data binding.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1