Multiple ViewModel folders with Telerik with MVVM Light

3 posts, 0 answers
  1. Rudy
    Rudy avatar
    1 posts
    Member since:
    Oct 2012

    Posted 14 Nov 2012 Link to this post

    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. Lance
    Lance avatar
    15 posts
    Member since:
    May 2012

    Posted 14 Nov 2012 Link to this post

    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




    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. 

  3. DevCraft banner
  4. Todor
    Todor avatar
    772 posts

    Posted 19 Nov 2012 Link to this post

    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,
    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.
Back to Top