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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:30:43+00:00 2026-05-14T07:30:43+00:00

I have this problem when i try to synchronize a observable list with listbox/view

  • 0

I have this problem when i try to synchronize a observable list with listbox/view
it displays the first item X times (x total amount of records in the list)
but it doesn’t change the variable’s

here is the XAML

   <ListBox x:Name="PostListView" BorderThickness="0"
                  MinHeight="300" 
                  Background="{x:Null}"
                  BorderBrush="{x:Null}"
                  Foreground="{x:Null}"
                  VerticalContentAlignment="Top"
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                  ScrollViewer.VerticalScrollBarVisibility="Disabled"
                 DataContext="{Binding Source={StaticResource PostListData}}"
                  ItemsSource="{Binding Mode=OneWay}"
                  IsSynchronizedWithCurrentItem="True"
                  MinWidth="332" SelectedIndex="0" SelectionMode="Extended" AlternationCount="1">
            <ListBox.ItemTemplate>
                <DataTemplate>
                  <DockPanel x:Name="SinglePost" VerticalAlignment="Top" ScrollViewer.CanContentScroll="True" ClipToBounds="True" Width="333" Height="70" d:LayoutOverrides="VerticalAlignment" d:IsEffectDisabled="True">
            <DockPanel.DataContext>
                <local:PostList/>
            </DockPanel.DataContext>
            <StackPanel x:Name="AvatarNickHolder" Width="60">
                            <Label x:Name="Nick" HorizontalAlignment="Center" Margin="5,0" VerticalAlignment="Top" Height="15" Content="{Binding Path=pUsername, FallbackValue=pUsername}" FontFamily="Arial" FontSize="10.667" Padding="5,0"/>
                <Image x:Name="Avatar" HorizontalAlignment="Center" Margin="5,0,5,5" VerticalAlignment="Top" Width="50" Height="50" IsHitTestVisible="False" Source="1045443356IMG_0972.jpg" Stretch="UniformToFill"/>
            </StackPanel>
                        <TextBlock x:Name="userPostText" Margin="0,0,5,0" VerticalAlignment="Center" FontSize="10.667" Text="{Binding Path=pMsg, FallbackValue=pMsg}" TextWrapping="Wrap"/>
        </DockPanel>
    </DataTemplate>
            </ListBox.ItemTemplate>
    </ListBox>  

and here is the ovservable list class

  public class PostList : ObservableCollection<PostData>
    {
        public PostList()
            : base()
        {
            Add(new PostData("this is test msg", "Cather", "1045443356IMG_0972.jpg"));
            Add(new PostData("this is test msg1", "t1", "1045443356IMG_0972.jpg"));
            Add(new PostData("this is test msg2", "t2", "1045443356IMG_0972.jpg"));
            Add(new PostData("this is test msg3", "t3", "1045443356IMG_0972.jpg"));
            Add(new PostData("this is test msg4", "t4", "1045443356IMG_0972.jpg"));
            Add(new PostData("this is test msg5", "t5", "1045443356IMG_0972.jpg"));
           // Add(new PostData("Isak", "Dinesen"));
          //  Add(new PostData("Victor", "Hugo"));
          //  Add(new PostData("Jules", "Verne"));
        }
    }

    public class PostData
    {
        private string Username;
        private string Msg;
        private string Avatar;
        private string LinkAttached;
        private string PicAttached;
        private string VideoAttached;

        public PostData(string msg ,string username, string avatar=null, string link=null,string pic=null ,string video=null)
        {
            this.Username = username;
            this.Msg = msg;
            this.Avatar = avatar;
            this.LinkAttached = link;
            this.PicAttached = pic;
            this.VideoAttached = video;
        }

        public string pMsg
        {
            get { return Msg; }
            set { Msg = value; }
        }

        public string pUsername
        {
            get { return Username; }
            set { Username = value; }
        }

        public string pAvatar
        {
            get { return Avatar; }
            set { Avatar = value; }
        }

        public string pLink
        {
            get { return LinkAttached; }
            set { LinkAttached = value; }
        }

        public string pPic
        {
            get { return PicAttached; }
            set { PicAttached = value; }
        }

        public string pVideo
        {
            get { return VideoAttached; }
            set { VideoAttached = value; }
        }
    }

Any ideas ?

  • 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-14T07:30:44+00:00Added an answer on May 14, 2026 at 7:30 am

    You are creating a new DataContext (PostList) every time a template is created.

    In the ListBox, set the ItemsSource to a new PostList.

    The ListBox will assign each instance of PostData to each copy of the DataTemplate and set it as the DataContext of the root element.

    tl;dr: Get rid of

    <DockPanel.DataContext>
        <local:PostList/>
    </DockPanel.DataContext>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 442k
  • Answers 442k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the UISwitch's .tag property to store an… May 15, 2026 at 5:57 pm
  • Editorial Team
    Editorial Team added an answer These lines look wrong to me: lprcCurr = new SDL_Rect;… May 15, 2026 at 5:57 pm
  • Editorial Team
    Editorial Team added an answer Use SET NOCOUNT ON in the trigger to suppress (xx… May 15, 2026 at 5:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.