Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should constants (Label Text etc) come in WPF MVVM application

Tags:

c#

.net

mvvm

wpf

Where should I create constants for Label Text, Button Text etc in a WPF MVVM application?

Is the best practice to:-

Creating static properties in ViewModel

Creating an nested class in the Model class and exposing it through a property?

Any other way.

Please advise. I am new to MVVM.

like image 731
ganeshran Avatar asked Dec 08 '25 20:12

ganeshran


1 Answers

Well I really liked and used this approach in my application. It uses standard Resx file for storing strings and uses Markup Extension for connecting view and the strings in resx file. You won't have to do any dirty trick in View Model or Model. I think resx file is best place for storing constant strings which end user will see. I used this solution for also changing the language of application at runtime. Even if your requirements are simple and you don't want fancy stuff you can use approach specified in post. It is really neat approach and places strings where they should be place (in resx). In next step you can directly bind text in resx with your label/button or anything you like.

like image 128
Haris Hasan Avatar answered Dec 11 '25 08:12

Haris Hasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!