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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:21:09+00:00 2026-05-25T13:21:09+00:00

The problem begins at this post: Using binding to a List<UserControl> how can I

  • 0

The problem begins at this post: Using binding to a List<UserControl> how can I do for not showing the controls

I was designing something like this:

List<Container>
(Below container properties)
    - Objective: string
    - Problems: List<ProblemUserControl>

ProblemUserControls is a UserControl where contais an extra property called Problem. But the above post a person suggest me use MVVM Pattern. I’m investigating but, I’m still confused or I need a little of help to understand the pattern in WPF.

  • 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-25T13:21:10+00:00Added an answer on May 25, 2026 at 1:21 pm

    Here is a example to illustrate using MVVM. Note that there is no need to have a list of usercontrols and indeed this would be considered incorrect from an MVVM viewpoint.

    This is based on the default WPF application template in Visual studio.

    Here are the classes involved.

    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler changed = PropertyChanged;
            if (changed != null)
            {
                changed(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    
    public class Container : ViewModelBase
    {
        private string m_Objective;
        private ProblemCollection m_Problems;
    
        public Container()
        {
            m_Problems = new ProblemCollection();
        }
    
        public string Objective
        {
            get { return m_Objective; }
            set
            {
                m_Objective = value;
                OnPropertyChanged("Objective");
            }
        }
    
        public ProblemCollection Problems
        {
            get { return m_Problems; }
            set
            {
                m_Problems = value;
                OnPropertyChanged("Problems");
            }
        }
    }
    
    public class Problem : ViewModelBase
    {
        private string m_Name;
    
        public string Name
        {
            get { return m_Name; }
            set
            {
                m_Name = value;
                OnPropertyChanged("Name");
            }
        }
    }
    
    public class ProblemCollection : ObservableCollection<Problem>
    {
    }
    

    And the main window. Note that I’ve commented out your rectangle to show the bindings

    <Window x:Class="StackOverflowDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525">
      <Grid>
        <TextBlock TextWrapping="Wrap" Text="{Binding Objective}" Grid.Column="0" VerticalAlignment="Center"
            FontWeight="Bold" />
        <ItemsControl ItemsSource="{Binding Problems}">
          <ItemsControl.ItemTemplate>
            <DataTemplate>
              <!--<Rectangle Stroke="Black" Height="20" Width="20" Margin="1,0" />-->
              <TextBlock Text="{Binding Path=Name}" />
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ItemsControl>
      </Grid>
    </Window>
    

    MainWindow.cs

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
    
            // Create dummy test data.
            // Normally this will be passed to the window or set externally
            var container = new Container();
            container.Problems.Add(new Problem {Name = "Foo"});
            container.Problems.Add(new Problem {Name = "Bar"});
            container.Problems.Add(new Problem {Name = "hello"});
            container.Problems.Add(new Problem {Name = "world"});
    
            DataContext = container;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to my previous post Problem with downloading multiple files using AsyncTask
Using the answer Generating the Image from a Controller from this post , I
I would like to solve the following problem using constraints but i actually don't
this is my first post to stack overflow! I'm using SlimDX for a game
This problem is baffling me: BEGIN; INSERT INTO sub_users(user_id, email) SELECT user_id FROM users
This is my problem - shortly: var c1:TClass1; c2:TClass2; begin c1 := c1.Create; c2
Problem: Given a list of strings, find the substring which, if subtracted from the
Problem Language: C# 2.0 or later I would like to register context handlers to
I have a problem where I need to make a multi-colored wheel spin using
I have a problem when i try to get the direct download link using

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.