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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:11:49+00:00 2026-06-17T08:11:49+00:00

This is a problem I’ve been trying to solve for a couple of days

  • 0

This is a problem I’ve been trying to solve for a couple of days but I’m yet to find a good solution.

I have a main WPF window which contains a StackPanel. I also have a class called “MessageManagement” which contains a List of custom WPF controls called “MessagePreview”.

MessagePreview

<UserControl x:Class="FinalYearProject.MessagePreview"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="58" d:DesignWidth="254" Background="White" BorderThickness="1" BorderBrush="#FF320000">
<Grid Name="grid1">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50" MaxWidth="50" MinWidth="50" />
        <ColumnDefinition Width="197*" MinWidth="20" />
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="1" Name="grid2">
        <Grid.RowDefinitions>
            <RowDefinition Height="31*" />
            <RowDefinition Height="34*" />
            <RowDefinition Height="33*" />
        </Grid.RowDefinitions>
        <Label Content="-ERROR-" Height="28" HorizontalAlignment="Left" Margin="2,1,0,0" Name="senderLabel" VerticalAlignment="Top" Foreground="#FF0000B4" Grid.RowSpan="2" />
        <Label Content="-ERROR-" Height="33" HorizontalAlignment="Left" Name="previewLabel" VerticalAlignment="Top" Margin="-1,17,0,0" Grid.RowSpan="3" />
        <Label Content="-Error-" Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="0,16,6,0" Name="timeLabel" VerticalAlignment="Top" Grid.RowSpan="2" Width="196" />
    </Grid>
    <Grid Name="grid3">
        <Grid.RowDefinitions>
            <RowDefinition Height="29*" />
            <RowDefinition Height="27*" />
        </Grid.RowDefinitions>
        <Image Height="38" HorizontalAlignment="Center" Margin="3,0,6,20" Name="image1" Stretch="Fill" VerticalAlignment="Bottom" Width="41" Source="/FinalYearProject;component/Images/twitter-bird-light-bgs.png" Grid.RowSpan="2" />
        <CheckBox Height="16" Margin="15,0,22,6" Name="checkBox" VerticalAlignment="Bottom" Grid.Row="1" IsChecked="False" />
    </Grid>
</Grid>

MessageManagement

List<MessagePreview> unread = new List<MessagePreview>();

    public bool messagesLocked()
    {
        foreach (MessagePreview m in unread)
        {
            if ((bool)m.checkBox.IsChecked)
                return true;
        }
        return false;
    }

MainWindow C#

MessageManagement messageManagement;

MessagesPanel1 is a blank StackPanel inside MainWindow

if (!messageManagement.messagesLocked())
{
       foreach (Message m in messageManagement.getListOfMessages()
       {
              MessagesPanel1.Children.Add(m)
       }
}

When you add the custom control to the StackPanel it creates a duplicate of the original, which means changing a value on the controls in the StackPanel does not affect the controls in my MessageManagement List.

Is there a way that I can reference my original controls so that they change together? I looked into DataBinding but I’m not sure if that’s the right area.

  • 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-17T08:11:50+00:00Added an answer on June 17, 2026 at 8:11 am

    Again, You do not make a List of UI elements in WPF. You use an ItemsControl and set its ItemTemplate Property to whatever UI you need to represent your items:

     <ItemsControl ItemsSource="{Binding Messages}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <!-- Everything you placed in your usercontrol, or else an instance of your usercontrol itself -->
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem pops around the network for years, I've found no good solution yet.
This problem looks trivial, but I can't find the solution. When I create a
This problem must have been solved a million times, but Google has not been
This problem has been kicking my butt for a few days now. I have
This problem seems very simple to me, but I've been unable to fix it,
This problem has been bothering me for sometime now, I have not settled on
This problem has been solved before, but I'm just not getting it with examples
This problem has been bugging me for a while. I have to load a
This problem probably has been discussed, but this one is slightly different. I'm using
This problem is probably very simple to solve but it is not clear to

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.