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 146517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:37:02+00:00 2026-05-11T08:37:02+00:00

Having read all the StackOverflow entries regarding Model-View-ViewModel architecture along with most of the

  • 0

Having read all the StackOverflow entries regarding Model-View-ViewModel architecture along with most of the readily available resources on the net I have come to the conclusion that it is the de-facto standard for building SOLID Silverlight apps.
I started to plan my next application using this architecture. One of the requirements for the application is to build or change the visual component structure. For example, responding to user interaction I would like to programmatically append an unknown-at-compile-time number of Rectangles and Ellipses to a specific Canvas or Canvases.
I started to twist my mind to apply the MVVM pattern and think where the code responsible for attaching the new components should go. I concluded that it doesn’t belong to any of the MVVM layers and therefore it is impossible to apply this architecture in scenarious where you have to manipulate the component tree at runtime.
Is there a way to still use Model-View-ViewModel in these kind of scenarious or it is only limited to work with a fixed View component structure?

  • 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. 2026-05-11T08:37:03+00:00Added an answer on May 11, 2026 at 8:37 am

    Don’t manipulate the component tree. Instead, manipulate a model that represents the component tree. Then have your view bind to the various collections and properties in that model to produce its visuals.

    What follows is a really simplified example. It just shows the concepts – please don’t take it as indicative of how you should factor your code.

    First, my model:

    public abstract class Shape {     public double Left { get; set; }     public double Top { get; set; } }  public class Rectangle : Shape {     public double Width { get; set; }     public double Height { get; set; } } 

    Next, I expose a collection of said shapes (you would use another model to contain this collection). Then I bind to it in my view:

    <Window x:Name='_root' x:Class='WpfApplication1.Window1'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'     xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:local='clr-namespace:WpfApplication1'     Title='Window1' Height='300' Width='300'>     <Window.Resources>         <DataTemplate DataType='{x:Type local:Rectangle}'>             <Rectangle Width='{Binding Width}' Height='{Binding Height}' Stroke='Black'/>         </DataTemplate>     </Window.Resources>     <ItemsControl DataContext='{Binding ElementName=_root}' ItemsSource='{Binding Shapes}'>         <ItemsControl.ItemsPanel>             <ItemsPanelTemplate>                 <Canvas/>             </ItemsPanelTemplate>         </ItemsControl.ItemsPanel>         <ItemsControl.ItemContainerStyle>             <Style>                 <Setter Property='Canvas.Left' Value='{Binding Left}'/>                 <Setter Property='Canvas.Top' Value='{Binding Top}'/>             </Style>         </ItemsControl.ItemContainerStyle>     </ItemsControl> </Window> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having read an existing post on stackoverflow and done some reading around on the
I am really lost in all the encoding/decoding issues with Python. Having read quite
I couldn't find answer after having read all the following: PEP 338 Executing modules
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service
Having read up on quite a few articles on Artificial Life (A subject I
Having read Fowler's Refactoring for a while, I still often catch myself thinking I
Having read Joe Armstrong's book and watched Kevin Smith screencasts I've built a simple
Having read this link on RBAR and this , my understanding of RBAR amounts
Having read the documentation of Java's String class, it doesn't appear to support popping
After having read that QuickSilver was no longer supported by BlackTree and has since

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.