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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:55:20+00:00 2026-05-17T20:55:20+00:00

I have a data bound UI. When I change the underlying data the UI

  • 0

I have a data bound UI. When I change the underlying data the UI updates fine but the controls appear to remain subscribed to my PropertyChanged events.

I have the following:

  • An ItemsControl bound to ListA

  • Each item ListA contains a sub list
    ListB that is displayed using another
    ItemsControl

  • Each item ListB is displayed using a
    TextBox bound to a string property
    via INotifyPropertyChanged

Here is the XAML:

<UserControl x:Class="SilverlightBindingTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <UserControl.Resources>

        <DataTemplate x:Key="DataTempl" >
            <TextBox Text="{Binding Value, Mode=TwoWay}"/>
        </DataTemplate>

        <DataTemplate x:Key="PageTempl" >
            <ItemsControl ItemsSource="{Binding Datas}" ItemTemplate="{StaticResource DataTempl}"></ItemsControl>
        </DataTemplate>

    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel>
            <ItemsControl ItemsSource="{Binding Pages}" ItemTemplate="{StaticResource PageTempl}"></ItemsControl>
            <Button Content="Swap list" Click="ButtonClick1"></Button>
            <Button Content="Change base data" Click="ButtonClick2"></Button>
        </StackPanel>
    </Grid>
</UserControl>

Here is the code:

using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Collections.Generic;

namespace SilverlightBindingTest
{
   public partial class MainPage : INotifyPropertyChanged
   {
      private List<DataGroupClass> pages1 = new List<DataGroupClass>();
      private List<DataGroupClass> pages2 = new List<DataGroupClass>();

      public MainPage()
      {
         InitializeComponent();
         List<DataClass> group = new List<DataClass>();
         group.Add(new DataClass("value 1"));
         group.Add(new DataClass("value 2"));
         group.Add(new DataClass("value 3"));
         pages1.Add(new DataGroupClass(group));

         group = new List<DataClass>();
         group.Add(new DataClass("value 4"));
         group.Add(new DataClass("value 5"));
         group.Add(new DataClass("value 6"));
         pages2.Add(new DataGroupClass(group));
         DataContext = this;
      }

      private List<DataGroupClass> pages = new List<DataGroupClass>();
      public List<DataGroupClass> Pages
      {
         get { return pages; }
         set
         {
            pages = value;
            PropertyChangedEventHandler h = PropertyChanged;
            if (h != null)
            {
               h(this, new PropertyChangedEventArgs("Pages"));
            }
         }
      }

      private void ButtonClick1(object sender, RoutedEventArgs e)
      {
         Debug.WriteLine("-------------------\n");
         if (Pages == pages1)
         {
            Pages = pages2;
         }
         else
         {
            Pages = pages1;
         }
      }

      private bool toggle;
      private void ButtonClick2(object sender, RoutedEventArgs e)
      {
         if (toggle)
         {
            pages1[0].Datas[0].Value = "tim";
            pages2[0].Datas[0].Value = "lajos";
         }
         else
         {
            pages1[0].Datas[0].Value = "joe";
            pages2[0].Datas[0].Value = "james";
         }
         toggle = !toggle;
      }

      #region INotifyPropertyChanged Members

      public event PropertyChangedEventHandler PropertyChanged;

      #endregion
   }

   public class DataClass : INotifyPropertyChanged
   {
      private string value;
      public string Value
      {
         get
         {
            Debug.WriteLine("Get Value:" + value);
            return value;
         }
         set
         {
            Debug.WriteLine("Set Value: " + this.value + " => " + value);
            this.value = value;
            PropertyChangedEventHandler h = PropertyChanged;
            if (h != null)
            {
               h(this, new PropertyChangedEventArgs("Value"));
            }
         }
      }

      public DataClass(string value)
      {         
         Value = value;
      }

      public event PropertyChangedEventHandler PropertyChanged;
   }

   public class DataGroupClass
   {
      private List<DataClass> datas;
      public List<DataClass> Datas
      {
         get
         {
            Debug.WriteLine("Get Datas");
            return datas;
         }
         set
         {
            Debug.WriteLine("Set Datas");
            datas = value;
         }
      }

      public DataGroupClass(List<DataClass> datas)
      {         
         Datas = datas;
      }
   }
}

Here is the trace output:

Click “Swap list” ten times (all looks OK):

 -------------------

 Get Datas
 Get Value:value 1
 Get Value:value 2
 Get Value:value 3
-------------------

 Get Datas
 Get Value:value 4
 Get Value:value 5
 Get Value:value 6
-------------------

 Get Datas
 Get Value:value 1
 Get Value:value 2
 Get Value:value 3
-------------------

 Get Datas
 Get Value:value 4
 Get Value:value 5
 Get Value:value 6
 -------------------

 Get Datas
 Get Value:value 1
 Get Value:value 2
 Get Value:value 3
 -------------------

 Get Datas
 Get Value:value 4
 Get Value:value 5
 Get Value:value 6
 -------------------

 Get Datas
 Get Value:value 1
 Get Value:value 2
 Get Value:value 3
 -------------------

 Get Datas
 Get Value:value 4
 Get Value:value 5
 Get Value:value 6
 -------------------

 Get Datas
 Get Value:value 1
 Get Value:value 2
 Get Value:value 3
 -------------------

 Get Datas
 Get Value:value 4
 Get Value:value 5
 Get Value:value 6
 -------------------

 Get Datas
 Get Value:value 1
 Get Value:value 2
 Get Value:value 3

Click “Change base data” (See multiple calls into Get Value):

    -------------------

    Get Datas 
    Get Value:value 1 
    Get Value:value 2 
    Get Value:value 3 
    Get Datas 
    Set Value: value 1 => joe 
    Get Value:joe  
    Get Value:joe 
    Get Value:joe 
    Get Value:joe 
    Get Value:joe 
    Get Value:joe 
    Get Datas 
    Set Value: value 4 => james 
    Get Value:james 
    Get Value:james 
    Get Value:james 
    Get Value:james 
    Get Value:james 

I assume I have missed something out but what?

Any help greatly appreciated!

  • 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-17T20:55:20+00:00Added an answer on May 17, 2026 at 8:55 pm

    Nope you haven’t missed something out. There are still some UI elements that remain uncollected by the garbage collector at the time you press “change base data”. The UI elements still hold on to their binding expression which in turn holds on the property changed event.

    Eventually those unused UI elements will be collected and will cease to listen to the property changed events.

    You can prove this (all though I certainly wouldn’t recommend that you do this real code) by placing GC.Collect() at the end of your button1 click code. By forcing the collection you’ll see you never get more than one read of the Value property.

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

Sidebar

Related Questions

I have the DGV bound to data and all the other controls properly. What
I have a problem with a data-bound DataGrid control, in that despite each column
I have an ItemsControl that is data bound to a list of decimal s.
I have a .NET repeater control that is data-bound to a List. As part
I have a list control in Flex that has been data bound to an
I have a WPF ListBox bound to a data object. Inside the listbox are
I have a custom NSTableView subclass which is bound to a data source (an
I have a list of objects (of type 'TrackedSet') that is data bound to
I have a windows form with DataBound DataGrid on it. Bound to a list
I have a Form in my application that displays some data. When I first

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.