10 Replies - 1104 Views - Last Post: 13 October 2014 - 01:31 PM Rate Topic: -----

#1 danbywinby  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 288
  • Joined: 06-January 13

Model/View/View Model folders?

Posted 13 October 2014 - 11:28 AM

Hi Guys

I was wondering if somebody would be able to tell me more about this Model/View/View Model structure thing?

As i was recently wondering if i am doing something wrong in my program as in program i am creating i only mostly have .xaml and .xaml.cs files in my 'Solution Explorer' window in Visual Studio. And recently online i found posts from people saying they have these 'Model, View and View Model' folders so i'm wondering should i have those folders? Am i doing something wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Model/View/View Model folders?

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Model/View/View Model folders?

Posted 13 October 2014 - 11:48 AM

It's up to you. Most first examples you'll find only have one View and one ViewModel so they don't use separate folders. Just as an example:
<Window x:Class="ToDoMVVM.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ToDoMVVM" 
        xmlns:viewmodels="clr-namespace:ToDoMVVM.ViewModels"

The last line points at a sub-folder named 'ViewModels' within the application's namespace.
    <window.Resources>
        <DataTemplate DataType="{x:Type viewmodels:HomeVM}">
            <TextBlock Text="Welcome to the ToDo Application!" FontSize="20" 
                       HorizontalAlignment="Center" VerticalAlignment="Center" />
        </DataTemplate>
        <DataTemplate DataType="{x:Type viewmodels:ToDoListVM}">

These refer to two ViewModel classes, in the 'ViewModels' folder.

So it's just a question of adjusting the namespace-references.

This post has been edited by andrewsw: 13 October 2014 - 11:50 AM

Was This Post Helpful? 0
  • +
  • -

#3 danbywinby  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 288
  • Joined: 06-January 13

Re: Model/View/View Model folders?

Posted 13 October 2014 - 11:57 AM

From the post above i am guessing that 'ViewModels' are basically just like 'UserControls'??

However i don't get what 'Views' and 'Models' are?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Model/View/View Model folders?

Posted 13 October 2014 - 12:01 PM

I assume you are going through an MVVM tutorial?

Quote

However i don't get what 'Views' and 'Models' are?

This suggests that you aren't?!

This post has been edited by andrewsw: 13 October 2014 - 12:02 PM

Was This Post Helpful? 0
  • +
  • -

#5 danbywinby  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 288
  • Joined: 06-January 13

Re: Model/View/View Model folders?

Posted 13 October 2014 - 12:07 PM

If i could find one that doesn't completely confuse me then i would.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Model/View/View Model folders?

Posted 13 October 2014 - 12:15 PM

Maybe this one:

MVVM Made Simple

I have one myself but it's not been up long so I haven't had much feedback about it yet. You should go through a smaller example first though.

You'll need to keep searching for one (or more) tutorials: it will be MUCH more difficult trying to reverse engineer something, and work out what's going on, AND WHY.
Was This Post Helpful? 1
  • +
  • -

#7 danbywinby  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 288
  • Joined: 06-January 13

Re: Model/View/View Model folders?

Posted 13 October 2014 - 12:22 PM

View Postandrewsw, on 13 October 2014 - 08:15 PM, said:

You'll need to keep searching for one (or more) tutorials: it will be MUCH more difficult trying to reverse engineer something, and work out what's going on, AND WHY.


Which is what i would basically be doing if i try to convert my current program to MVVM wouldn't i?
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Model/View/View Model folders?

Posted 13 October 2014 - 12:39 PM

Yes but as you don't understand what Views or Models are (as you've stated) you cannot do either currently.

MVVM is about understanding the pattern: the principles and philosophy behind it, not about moving files around.

Anyway, good luck ;)

This post has been edited by andrewsw: 13 October 2014 - 12:46 PM

Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6530
  • View blog
  • Posts: 14,446
  • Joined: 02-June 10

Re: Model/View/View Model folders?

Posted 13 October 2014 - 01:02 PM

Aside from understanding the concepts... Do you understand you can make folders in your Visual Studio solution?
If you're expecting VS to do the work for you, or for those folder to be created automagically you're wrong.
You can make whatever folders you like to help you organize your projects.
Was This Post Helpful? 0
  • +
  • -

#10 danbywinby  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 288
  • Joined: 06-January 13

Re: Model/View/View Model folders?

Posted 13 October 2014 - 01:23 PM

View PosttlhIn`toq, on 13 October 2014 - 09:02 PM, said:

Aside from understanding the concepts... Do you understand you can make folders in your Visual Studio solution?
If you're expecting VS to do the work for you, or for those folder to be created automagically you're wrong.
You can make whatever folders you like to help you organize your projects.


Seen as i saw a lot of posts from different people with the same folders i did expect that they were created automatically.

But if i do create my own folders do i then have to change the code??
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Model/View/View Model folders?

Posted 13 October 2014 - 01:31 PM

I demonstrated how you would need to change XAML in my first post:
<Window x:Class="ToDoMVVM.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ToDoMVVM" 
        xmlns:viewmodels="clr-namespace:ToDoMVVM.ViewModels"

In the cs-code you could also use:
using ToDoMVVM.ViewModels;

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1