This is a migrated thread and some comments may be shown as answers.

Multiple ViewModel folders with Telerik with MVVM Light

2 Answers 205 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rudy
Top achievements
Rank 1
Rudy asked on 14 Nov 2012, 03:27 PM
Good morning all! I am just getting started with the controls for Windows 7 and MVVM Light. I have a question about the resulting structure of a new project. My folders end up looking like this: Solution Explorer 
So, I now have a ViewModel folder from MVVM light and a ViewModels folder from Telerik. However the ViewModels folder now resides under the View folder. At this point, I am not sure where my actual Views and ViewModels should go.

My question is, what is the correct and or easiest way to start a new project? Should I create a Telerik project first and add in MVVM light second? Or, should I create an MVVM Light project first and then convert to a Telerik project using the Upgrade Wizard?

Or, is the project OK as is and I just have to put my Views and ViewModels in a particular folder?

Thanks for your help!

2 Answers, 1 is accepted

Sort by
0
Lance
Top achievements
Rank 2
answered on 14 Nov 2012, 06:43 PM
Hi Rudy,

This can also happen if you add a new Telerik Item to a project inside a subfolder (which it looks like you added an "About" page Telerik item to your "Views" folder). This happens because the Telerik Wizard automatically installs the ViewModel in the same folder level as you are placing the page.

Looking at your Solution Explorer you have

Beeville.ViewModel

and

Beeville.View.ViewModel

The folders inside your Views folder contain the commands for your Telerik application helper. When the ok button in the Messagebox for "Rate This App" or when the user clicks on a link in the About page, it will look for the command in the View > Commands folder.

You can keep it this way and everything will work fine. If you add a new Telerik Item to the View folder, the Wizard will add on to the existing structure. As far as the MainViewModel for the rest of your project is concerned, as long as the DataContext is is pointing to the right VM, everything will work as expected.

May I ask a question, in your App.xaml.cs file, which ViewModel is instantiated as App.ViewModel? It should be something like this:

static App()
{
     ViewModel = new LocationViewModel();
}
 
public static LocationViewModel ViewModel { get; set; }

This instantiates "MainViewModel as your app's Viewmodel. This is where you should put the objects for you DataItem class.

If you have the ability to start over, and want the Telerik Wizard to place the Wizard generated ViewModels in your project root, then add the About (or other Telerik Item) to the root folder. 

Lancelot
0
Todor
Telerik team
answered on 19 Nov 2012, 02:15 PM
Hi Rudy,

Thank you for your question.

Let me try to say it a little more simple. Your project should work as it is, however it will be much easier for you (or anyone else) to read the code and find what you search for, if it is organized in folders. As Lance explained, the Telerik wizard adds the item that you have chosen (About page in your case) and adds the files that it requires in a structure inside the selected folder. I think it would look much better if you right click the project and add new Telerik item there. This would add the ViewModels used by this item in the same folder as the ViewModels created my the MVVM framework. If you want your files organized in Views, you can move the About page to another folder like the Views folder that you have. Please note, that this might break some paths and you might need some adjustments like the CompanyLogo's source which will have to be changed from: Images/CompanyLogo.png to ../Images/CompanyLogo.png, for example, but in general its up to you how to combine the Telerik's resources and MVVM Light.

I hope this information is helpful and good luck with your application development, we'll be here in case you need help with RadControls for Windows Phone.

All the best,
Todor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
General Discussions
Asked by
Rudy
Top achievements
Rank 1
Answers by
Lance
Top achievements
Rank 2
Todor
Telerik team
Share this question
or