views:

27

answers:

1

Hello folks,

I have a ViewModel with Property int DepartmentColor. Of course I can not bind the int value to a CellStyle in XAML.

Should I make a IntToStyleConverter or should I fumble around with the Style class in the ViewModel like convert the int to a SolicColorBrush and assign it to a Style etc...

Is the latter the way to go with MVVM ?

A: 

Go the converter route. In addition I would title the property something to the effect of Department and not tie color to it as it makes it more tightly coupled to the UI. While the department may be Accounting coupling that to a color implies you are certain that it will be represented via a Color, whereas down stream it may be represented in some other visual fashion. You could also create the styles ahead of time and then simply select one and apply it via the converter, versus trying to create them in the code behind.

Aaron
Where is there a difference naming the property Department or DepartmentColor ? Department is already reserved for the Department`s name... Maybe I should explain: I have organizer/calendar with a DataGrid where each Department has its own Backcolor. So naming it DepartmentBackColor is not wrong, why should it be wrong? To your suggestion: When I create the styles then I create them in code-behind... I assume this as you have not written I should create them in the ViewMode.
Pascal
My belief is that you should not push UI type references into the ViewModel. Color is a direct relationship to the UI. Allow the UI to determine what to do with the department type, which may happen to be color in this instance. Create the Styles as reusable styles in a ResourceDictionary which can then be referenced in your code behind (converter).
Aaron
if I would have a Model with a property called DepartmentColor, I would understand your argumentation. But its the ViewModel`s Property DepartmentColor and the ViewModel is bound directly to the View. So why not Department"Color" ? I find it totally okish.
Pascal