Click here to Skip to main content
16,016,263 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have a generic question. I am writing a program that will eventually have data tables and so forth. I am trying to determine if I am on the right track for implementing mvvm correctly since this is my first application of such.

The application is currently just the foundation of the program. It is a simple window with a tab control.

The application is just controlling some layout features, but it is about to cross into using and manipulating data.

For example:
The main window and tab control have very basic XAML on there actual sheets. These pull in styles and designs from global resource dictionaries. The dictionaries control only the common layout and design elements. The views for these controls have some basic code behind that calls global functions and subs. The specific layout of the tabs and any controls within them are written into and read from XML. This information is stored into a collection of a custom class: one for the tabs themselves and the other for the controls within the tabs. Whenever the user changes the layout, the view fires a global function through its small code behind which makes adjustments to the collection. When the application is closed, the settings are saved to an XML file.

A similar flow will be done when certain controls are linked to SQL data but instead of a collection, I would like to use data tables. I know that in WinForms it was relatively easy to bind a data table to a number of controls. Based on the information that I have seen, the best option for two way communication is by using an obseravable collection. I am just not entirely sure if I am doing the project the correct way or if I should change things now before I become too involved.

Any suggestions or help articles would be greatly appreciated. I can read C# as well as vb if that helps.
Posted
Comments
PIEBALDconsult 14-Jan-14 18:45pm    
Someone will always say you're doing it wrong. Just do as you think best and don't woory about the Pattern du jour.
Punamchand Dhuppad 14-Jan-14 22:36pm    
If you understood MVVM pattern perfectly. Then you implemented it correctly.

What is the motivation to use MVVM?
See http://blog.lab49.com/archives/2650[^] or more speciffically: http://www.lab49.com/wp-content/uploads/2011/12/Jason_Dolinger_MVVM.wmv[^].
Cheers
Andi
 
Share this answer
 
I'm not sure I entirely understand what you are asking, but it seems to me that you are allowing the user to change layout of controls, and want to save the layout to a database, where currently you save the layout to XML.

It sounds to me like you would have a public method on a BaseViewModel class, called "SaveLayout()" or similar.

You code behind, instead of szaving your collection to XML would call that method on the VM

An appropriate "LoadLayout()" method would also be required.

So your Vm is responsible for obtaining the data from the database and providing it (whether you wanted to provide it as a DataTable or pre-converted into your existing collection is up to you - I personally don't like dataTables at the View level)

Your View then does exactly what it does with the collection now, replacing your existing "SaveLayoutToXml" function in the code behind with the VM.SaveLayout() method call.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900