1

I recently discovered the Windows Presentation Foundation (WPF) so this is a very new framework for me. I also have went over multiple tutorials on implementing a MVVM architecture but I am still not sure if this is the right approach for the task at hand because it is a lot more complex than all the examples that I have looked over.

What my program needs to accomplish:

The program will scan all the serial ports currently connected to the laptop and add all devices that are lasers produced by the company (this is determined by the firmware ID) to a selection combobox. The user will then choose a com-port/device and press a button to connect to it.

This will trigger the creation of a new window(view) and a new laser object(model) corresponding to the device that the user chose. Depending on the device that was picked, the window should contain the necessary fields to display the different sensors (e.g. power, current, temperature) and drivers that the laser has. There are about 10 different devices that the UI should be able to monitor and display the corresponding readings. Therefore, each type of device should have a corresponding view.

So first of all, would the MVVM architecture be the right approach?

If so, how would you implement such a design? Can you have an abstract base view class which contains all the fields that are necessary for all the devices and then concrete subclass that inherit from the base class?

Thank you in advance for your time!

Daniil K
  • 33
  • 1
  • 7
  • Each device window should be a dialog type (does not allow to interact with parent while open)? – Karolis Kajenas May 17 '16 at 19:40
  • WPF/MVVM would be *ideally* suited to that; one of its strengths is the ease of stuffing arbitrary chunks of UI into arbitrary parents. I don't know why you'd want an abstract base class with *every* property of *every* device in it; I'd make my base class a proper base class with only the common stuff, then have subclasses add what they need. BTW I expect you to get dinged here for "too broad", "opinion based", "mother didn't love me", "the bar I'm sitting in is too loud", etc. – 15ee8f99-57ff-4f92-890c-b56153 May 17 '16 at 19:40
  • @Carl not sure what you mean by dialog type, but each window should be a separate window that will have fields that are updated every second or so by the readings being obtained from the device and also a section for settings, where the user would be able to change some parameters such as the output power of the laser. – Daniil K May 17 '16 at 19:51
  • @edplunkett yes that's what I meant by the abstract class, sorry for my poor explanation. Thank you for your input! – Daniil K May 17 '16 at 19:54

1 Answers1

1

MVVM is the right choice for you.

Use DataTemplate and define your Views based on the selection create the ViewModel corresponding to the View to show up. Use ContentPresenter to switch ViewModels based on your selection.

Referance 1 Here you can understand how to switch View using DataTemplate

Referance 2 Here Understand MVVM

Referance 3 Example

Community
  • 1
  • 1
Abin
  • 2,868
  • 1
  • 23
  • 59