Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:21:20+00:00 2026-06-18T05:21:20+00:00

Is it true that if I create a ViewModel I need to create Model

  • 0

Is it true that if I create a ViewModel I need to create Model for it in MVVM pattern?

For example my task to create simple Menu in WPF app at the top of the window.

This is my View MainWindow.xaml

<Window x:Class="AppMvvm.View.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:vm="clr-namespace:AppMvvm.ViewModel"
    Title="{Binding DisplayName}" Height="350" Width="525"
    WindowStartupLocation="CenterScreen">

<Window.Resources>
    <Style x:Key="MenuItemStyle">
        <Setter Property="MenuItem.Command" Value="{Binding Command}" />
    </Style>
    <HierarchicalDataTemplate DataType="{x:Type vm:MenuItemViewModel}"
                              ItemsSource="{Binding Children}">
        <ContentPresenter Content="{Binding DisplayName}" />
    </HierarchicalDataTemplate>
</Window.Resources>

<DockPanel>
    <DockPanel DockPanel.Dock="Top">
        <Menu ItemsSource="{Binding MenuItems}" ItemContainerStyle="{StaticResource MenuItemStyle}"/>
    </DockPanel>


</DockPanel>
</Window>

Here is my ViewModel for MenuItemViewModel.cs

namespace AppMvvm.ViewModel
{
    public class MenuItemViewModel : ViewModelBase
    {

        public MenuItemViewModel(string menuItemName, IList<MenuItemViewModel> children)
        {
            base.DisplayName = menuItemName;
            this.Children = children;
        }

        public MenuItemViewModel(string menuItemName)
            : this (menuItemName, children: null)
        {
        }

        public MenuItemViewModel(string menuItemName, ICommand command)
        {
            base.DisplayName = menuItemName;
            this.Command = command;
        }

        public IList<MenuItemViewModel> Children { get; private set; }

        public ICommand Command { get; private set; }
    }
}

My class WorkspaceViewModel.cs that is base class for MainWindowViewModel.cs which is binded to the View

namespace AppMvvm.ViewModel
{
    using Helpers;

    public abstract class WorkspaceViewModel : ViewModelBase
    {
        #region Fields
        private IList<MenuItemViewModel> _menuItems;
        private RelayCommand _closeCommand;
        #endregion

        #region MenuItems
        public IList<MenuItemViewModel> MenuItems
        {
            get
            {
                if (_menuItems == null)
                    _menuItems = CreateMenuItems();
                return _menuItems;
            }
        }

        List<MenuItemViewModel> CreateMenuItems()
        {
            return new List<MenuItemViewModel>
                {
                    new MenuItemViewModel("File", CreateFileMenuItems()),
                    new MenuItemViewModel("Tools"),
                    new MenuItemViewModel("About")
                };
        }

        #region CreateFileMenuItems & Commands
        List<MenuItemViewModel> CreateFileMenuItems()
        {
            return new List<MenuItemViewModel>
                {
                    new MenuItemViewModel("New"),
                    new MenuItemViewModel("Exit", CloseCommand)
                };
        }

        public ICommand CloseCommand
        {
            get
            {
                if (_closeCommand == null)
                    _closeCommand = new RelayCommand(p => Close());
                return _closeCommand;
            }
        }

        void Close()
        {
            Application.Current.Shutdown();
        }
        #endregion

        #endregion
    }
}

Is it correct to do it in this way or I need to create a Model for the MenuItemViewModel class and do it another way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:21:21+00:00Added an answer on June 18, 2026 at 5:21 am

    Yes and no.

    The MVVM pattern by its very nature stipulates that you will have a Model, but this doesn’t mean that you need to fully implement MVVM.

    Exactly what you decide to do will depend on your project, and your understanding (or interpretation) of MVVM. I’ve taken an approach before that was a combination of MVVM with MVC – i.e. it had a V/VM and then a controller sitting behind it (the controller is almost like a super duper model). If you have a very simple application then there is no point making it complicated simply for the sake of pattern purity – stick with just a view and viewmodel if that suits your purposes.

    The thing to remember is that a pattern is simply a recipe or prescription of how to do something. There is no rule that says you should adhere to it rigidly, in many cases you may find that you can’t and you therefore either have to adapt a pattern or use several patterns – the key thing is to maintain consistency with what you do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understood how to create events, like that: var evt=document.createEvent('Event'); evt.initEvent('foo',true,true); window.dispatch(evt); Then anyone
I have a WPF application implemented using the MVVM framework that uses an ActiveX
I'm using the knockout mapping plugin to create a viewmodel from data that has
I'm fairly new to WPF, and I want to create an MVVM based application
I need a solution for this. I need to create a view model for
I'm writing an application in WPF using the MVVM pattern. In my application I've
I am using C# to create a view model that I later serialize into
Is it true that this does not necessarily mean the stream has been disposed
Question Is it true that C-style strings operations, on average, execute 5 times slower
Is it true that you cannot use COM Interop to expose COM properties? Everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.