How to handle ViewModel and Database in C#/WPF/MVVM App

Posted by Mike B on Stack Overflow See other posts from Stack Overflow or by Mike B
Published on 2010-03-23T04:01:34Z Indexed on 2010/03/23 4:11 UTC
Read the original article Hit count: 723

Filed under:
|
|
|

I have a task management program with a "Urgency" field. Valid values are Int16 currently mapped to 1 (High), 2 (Medium), 3 (Low), 4 (None) and 99 (Closed). The urgency field is used to rank tasks as well as alter the look of the items in the list and detail view.

When a user is editing or adding a new task they select or view the urgency in a ComboBox. A Converter passes Strings to replace the Ints. The urgency collection is so simple I did not make it a table in the database, instead it is a, ObservableCollection(Int16) that is populated by a method.

Since the same screen may be used to view a closed task the "Closed" urgency must be in the ItemsSource but I do not want the user to be able to select it. In order to prevent the user from being able to select that item in the ComboBox but still be able to see it if the item in the database has that value should I...

  1. Manually disable the item in the ComboBox in code or Xaml (I doubt it)
  2. Change the Urgency collection from an Int16 to an Object with a Selectable Property that the isEnabled property of the ComboBoxItem Binds to.
  3. Do as in 2 but also separate the urgency information into its own table in the database with a foreign key in the Tasks table
  4. None of the above (I suspect this is the correct answer)

I ask this because this is a learning project (My first real WPF and first ever MVVM project). I know there is rarely one Right way to do something but I want to make sure I am learning in a reasonable manner since it if far harder to Unlearn bad habits

Thanks

Mike

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvvm