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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:15:00+00:00 2026-05-20T13:15:00+00:00

I am creating some attached properties, one of which is a DataTemplate. The DataTemplate

  • 0

I am creating some attached properties, one of which is a DataTemplate. The DataTemplate should have a FrameworkElement that I’ve created defined in it so that the XAML declaration of all this looks like:

<SomeControl m:ItemsSource="{Binding Source}">
  <m:MyTemplate>
    <DataTemplate>
      <m:MyClass SomeDependency="{Binding Path}"/>
    </DataTemplate>
  </m:MyTemplate>
</SomeControl>

In the code for the MyTemplateProperty changed callback, it iterates over every item in Source and calls LoadContent() on the DataTemplate. It then sets the DataContext on the class returned by LoadContent() to the item from Source:

private static void MyTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
  var items = (d as SomeControl).GetValue(ItemsSourceProperty) as IList;
  var template = e.NewValue as DataTemplate;
  foreach(var item in items)
  {
    var myClass = template.LoadContent() as MyClass;
    myClass.DataContext = item;
  }
}

The strange thing here is that the first instance of MyClass created in this way gets binding updates (SomeDependencyProperty updates with the value that is in the item from ItemsSource), but none of the rest of the instances get updated.

I have verified that this should work properly by creating MyClass myself instead of the LoadContent call and setting the bindings using BindingOperation.SetBinding like:

foreach(var item in items)
{
  var myClass = new MyClass();
  BindingOperations.SetBinding(myClass, MyClass.SomeDependencyProperty, new Binding("Path");
  myClass.DataContext = item;
}

Does anyone know why the LoadContent call seems to produce objects that do not all update their bindings when the DataContext changes? What is different about the LoadContent call than just creating the objects myself?

  • 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-20T13:15:01+00:00Added an answer on May 20, 2026 at 1:15 pm

    It was pointed out by a co-worker that nothing was holding on to the instances of MyClass. Adding a way for these instances to be referenced solved the issue I was seeing. It doesn’t quite explain why the first instance would get updates and the rest wouldn’t, but it has fixed my problem.

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

Sidebar

Related Questions

I have application which has some networking code which runs asynchronously. I have attached
I have a loop that when it is called, creates a div with some
I have created one service. Now I am trying to access database in onstart()
I'm having some troubles creating a relativeLayout programmatically.For better understanding I attached a picture
I created a simple WCF web service that has one method: SubmitTicket(flightticket ft, string
I have some .NET 4 entity framework objects that I get from the DB,
Does anyone have a good example of creating a WPF custom control or some
In Sitecore I have created a custom field (via this recipe: http://sdn.sitecore.net/Articles/API/Creating%20a%20Composite%20Custom%20Field/Adding%20a%20Custom%20Field%20to%20Sitecore%20Client.aspx ) The
I have a file that I am creating on the fly like this: //
I'm creating some reports in Google Analytics. I am trying to write a RegEx

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.