0

Three GUIs with almost the same design are started from different application menus and all of them will have a:

  • Search TextField
  • ComboBox for category selection
  • ListBox showing the result based on category

and of course a couple of buttons for searching etc.

Suppose the menus are named Add new A, Add new B, Add new C.

When Add new A is clicked, it should start the "base/parent" GUI with the above components.

When Add new B is clicked, it should start a GUI the same as base except it should also have a couple of radiobuttons.

The same goes for Add new C, only differences are a couple of simple controls.

How is this effectively done using WPF? Should I design one GUI with all elements and hide e.g. the radiobuttons if started from "Add new A"?

Or should I use three different XAMLs and end up with most of the code and design elements being the same.

Ramon
  • 245
  • 2
  • 4
  • 15

2 Answers2

0

Or should I use three different XAMLs and end up with most of the code and design elements being the same.

I think this depends on what it is you're trying to represent graphically. When I worked on a color picker, I created multiple controls that all contained the same controls, but different properties and conversion algorithms. In most MVVM implementations I've seen, it is indeed done this way.

Another thing you can consider is making one base UserControl, such as Panel that contains all the controls and properties that all the UserControls require, and then creating subsequent UserControls like CalendarPanel or NotebookPanel, which are based of Panel, but specify new controls and properties.

An example of this can be found here: How can a WPF UserControl inherit a WPF UserControl?

It is complicated to learn at first, but super fun once you get the hang of it :)

Community
  • 1
  • 1
0

If all three views can have single view model, then add a Mode enum to your view model, and basing on this enum show/hide some parts in your view. This approach will be easiest to test and maintain.

Sometimes though, there are places in the application that should look similar, but have different view models. Then I suggest splitting these view models to smaller ones, that can be shared. Then you'll be able to compose your views from smaller, shared components.