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

  • SEARCH
  • Home
  • 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 4038230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:26:50+00:00 2026-05-20T12:26:50+00:00

I have an application which I am trying to design using the MVVM pattern.

  • 0

I have an application which I am trying to design using the MVVM pattern. In my Models I have Group and Case. A Group may contain other groups as well as cases. Now, I want to display these in a TreeView in my View. So because Groups may contain other groups and cases, the tree can end up looking something like this:
Group
—Group
—-Case
—-Case
—Group
—-Group
—-Case
—Case
Case

I have my View attached to a ViewModel which contains an ObservableCollection of Groups. My problem is that the only way I can get the TreeView to display as I would like it to is to use a HierarchicalDataTemplate in the resources pointed to the datatype (Group or Case), which I feel like is breaking MVVM (where the View should not know about the Model).

This works:

 <UserControl.Resources>
    <HierarchicalDataTemplate DataType="{x:Type models:Group}" ItemsSource="{Binding Children}">
        <TextBlock Text="{Binding GroupName}" />
    </HierarchicalDataTemplate>
    <DataTemplate DataType="{x:Type models:Case}">
        <TextBlock Text="{Binding CaseName}" />
    </DataTemplate>
</UserControl.Resources>

and for the TreeView:

<TreeView ItemsSource="{Binding AvailableCaseGroups}" />

Is this breaking the spirit of MVVM? How can I do this otherwise?

  • 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-05-20T12:26:51+00:00Added an answer on May 20, 2026 at 12:26 pm

    I don’t think it’s breaking MVVM at all, if the View knows about the ViewModel.
    Surely, using Model details in the View is not fine with MVVM.
    To work around this you could just build up some hierarchical structure of ViewModels – MainViewModel
    — GroupViewModel g1
    —GroupViewModel g1a
    —CaseViewModel c1b
    — GroupVieModel g2
    …
    Then it’s no longer a structural detail of your Model but one of your ViewModel and can be used by the View. If the Model may structurally change in the future, become a flat list or s.th., your ViewModel can still stick to the old hierarchy (transform the Model) and your View is still valid.

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

Sidebar

Related Questions

I'm trying to create an silverlight application using the MVVM design pattern. It's a
I have an application in which I am trying to refresh the list after
I have a C application which provides a shell for entering commands. I'm trying
I have a multithreaded application, in which I'm trying to render with different threads.
I have the following work on my application, in which I am trying to
I'm trying to learn how to design an application which has several different user
I am trying to validate User Input in Windows Forms Application (using MVP design
I have been trying different techniques while designing this application, which to me is
I have an ASP.Net Web Forms application in which I'm using forms-based authentication with
I have application which uses Sherlock ActionBar package. The application uses platform-specific behavior for

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.