MVVM: how to pass constructor variables from the ViewModel to the View

This forum is meant for anything you would like to share with other visitors
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

MVVM: how to pass constructor variables from the ViewModel to the View

Post by Frank Maraite »

Hi Wolfgang,

did you ever tried ValueConverters? You can use them to convert for example numerical values to logic and bind to visibility.

Why not use two panels wich double the labels and text fields. One with italian first and german second, the other the other way. Bind text fields and labels on both panels to the same properties. Then bind visibility of panels to what you want.

And of course it does make any difference doing it in code or via XAML.

Frank
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how to pass constructor variables from the ViewModel to the View

Post by wriedmann »

Hi Frank,

yes, I've played a bit with ValueConverters. And as always, for every problem there are a couple of solutions, and I like the possibility to select the way I prefer.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how to pass constructor variables from the ViewModel to the View

Post by wriedmann »

Hi Phil,

personally I don't like graphical windows editors, and specially for WPF I feel a GUI editor limits the dynamic possibilities too much.
I prefer using a more data driven approach, and therefore I prefer to build my windows in code like most HTML guys.

Wolfgang

P.S. this is the last time I'm trying to explain why I use the code based approach. I don't expect that others follow my way - but maybe it could be useful for some special need.
And another thing: in the Holy Bible there is a saying: "the Sunday is made for the people, and not the people for the Sunday". Patterns and rules are there to help us, not to make our life too complicated. Therefore I don't have any problem to break a rule sometimes when I know why.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

MVVM: how to pass constructor variables from the ViewModel to the View

Post by Phil Hepburn »

Okay, understood ;-0)

But remember that many others read our postings so we need to get things as right as possible for them too. :lol:

Did you explore using a 'UserControl' which can then be instantiated (more than once when required), and placed on one or more Tabs of a Tab Control. This will increase the 'real estate' or form area without need to resize and re-jiggle the rest of the form and its controls - no matter how many tabs you require..

'UserControl's go in 'ContentControl's and all your controls on the UC can be data bound as easily as the main form.

This way you could even have more than one style of UC and select which you want to display at Initialization time.

HTH,
See you on Sunday then :whistle: :blink: :P

Phil.
Wales, UK.
Post Reply