Click here to Skip to main content
15,354,345 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 8:07
Membereddieangel21-Jan-14 8:07 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 8:48
professionalJason Gleim21-Jan-14 8:48 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 9:14
Membereddieangel21-Jan-14 9:14 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 9:42
professionalJason Gleim21-Jan-14 9:42 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 10:12
Membereddieangel21-Jan-14 10:12 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 10:25
professionalJason Gleim21-Jan-14 10:25 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 11:29
Membereddieangel21-Jan-14 11:29 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim22-Jan-14 4:28
professionalJason Gleim22-Jan-14 4:28 
Sorry for the delay getting back...

I understand your concerns. You didn't say that you are using MVVM but since you are talking about a model class I'm guessing you are, in fact, using it. If that is the case, you should put all of your database code in the model. The idea of the model is to hide the details of the backing data store so you could switch it out if you needed. So it may feel dirty but that is exactly what you are supposed to be doing.

I have fallen into a pattern where I usually create two classes for data. I'll call them DataObject and DataModel (really xxxxObject and xxxxModel as appropriate). DataObject represents the actual data and is typically nothing more than a class with a bunch of public properties. I usually inherit INotifyPropertyChanged and INotifyDataError on that class so that it can alert to value changes and it can alert to bad values.

The second class, DataModel, is where I put the data access functions. This class is data source specific and usually implements an interface I have specified with the functions I'll need. In your case, this class might expose a function like:
C#
public CategoryBase GetCategoryById(int Id)

which would obviously return a category based on an Id. In your ViewModel you would have a property which would take a category ID and in the setter you would call the GetCategoryById then use the results to set the category and Id on the property exposing that data object. As long as the underlying DataObject implements INPC and you have bound to a non-null category object at startup, then the category and Id should follow along with changes in the Id sourced from the combobox.

The grid complicates things a bit because you have a collection of the data objects but that is pretty easy to work around. If you are uncomfortable wiring it up from the property setter for the Id property, remember that Combobox exposes a selection changed event. You could bind a command to that and use that as a jump point to call the DB fetch method and set the category data object.

Ultimately though... I suggest you take MVVM as a suggestion and not a set of hard and fast rules. Like a lot of stuff in software development, there is always some scenario that doesn't fit the rules so we end up breaking them to make it work. If you figure out a system that works, then consider it a success. Just document the code so the next guy can see why you did what you did and why you broke the rule. Shucks | :-\
GeneralRe: Combobox / Textblock field Pin
eddieangel22-Jan-14 5:34
Membereddieangel22-Jan-14 5:34 
QuestionHow to stop repeating animation Pin
Member 1001614016-Jan-14 12:25
MemberMember 1001614016-Jan-14 12:25 
AnswerRe: How to stop repeating animation Pin
Varsha Ramnani20-Jan-14 22:41
professionalVarsha Ramnani20-Jan-14 22:41 
QuestionWPF Checkbox Binding Question Pin
Kevin Marois10-Jan-14 8:38
professionalKevin Marois10-Jan-14 8:38 
AnswerRe: WPF Checkbox Binding Question Pin
Meshack Musundi12-Jan-14 8:28
professionalMeshack Musundi12-Jan-14 8:28 
AnswerRe: WPF Checkbox Binding Question Pin
eddieangel21-Jan-14 7:53
Membereddieangel21-Jan-14 7:53 
QuestionVS2013: cannot locate resource Pin
Anthony.Canossi9-Jan-14 4:47
MemberAnthony.Canossi9-Jan-14 4:47 
AnswerRe: VS2013: cannot locate resource Pin
Mycroft Holmes9-Jan-14 11:49
professionalMycroft Holmes9-Jan-14 11:49 
GeneralRe: VS2013: cannot locate resource Pin
Anthony.Canossi9-Jan-14 21:25
MemberAnthony.Canossi9-Jan-14 21:25 
GeneralRe: VS2013: cannot locate resource Pin
Mycroft Holmes9-Jan-14 21:37
professionalMycroft Holmes9-Jan-14 21:37 
GeneralRe: VS2013: cannot locate resource Pin
Anthony.Canossi9-Jan-14 22:28
MemberAnthony.Canossi9-Jan-14 22:28 
AnswerRe: VS2013: cannot locate resource Pin
Meshack Musundi12-Jan-14 7:53
professionalMeshack Musundi12-Jan-14 7:53 
GeneralRe: VS2013: cannot locate resource Pin
Anthony.Canossi12-Jan-14 21:31
MemberAnthony.Canossi12-Jan-14 21:31 
QuestionDragging A Control - Problem Pin
Kevin Marois8-Jan-14 10:13
professionalKevin Marois8-Jan-14 10:13 
AnswerRe: Dragging A Control - Problem Pin
Meshack Musundi12-Jan-14 7:58
professionalMeshack Musundi12-Jan-14 7:58 
Questionupdate linq query result Pin
amigoface5-Jan-14 3:12
Memberamigoface5-Jan-14 3:12 
QuestionLearn Wpf Pin
Member 105030394-Jan-14 2:00
MemberMember 105030394-Jan-14 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.