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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:11:27+00:00 2026-06-12T22:11:27+00:00

I am transfering FrameworkElement from StackPanel on WPF Page to programmatically created StackPanel. At

  • 0

I am transfering FrameworkElement from StackPanel on WPF Page to programmatically created StackPanel. At a certain point I need to refresh bindings and get property values.

At this point FrameworkElement.DataContext has correct value and BindingExpression.Status==BindingStatus.Unattached for all binding expressions. I execute BindingExpression.UpdateTarget, but property values are empty.

I found source code for BindingExpression.UpdateTarget():

    public override void UpdateTarget() 
    {
        if (Status == BindingStatus.Detached) 
            throw new InvalidOperationException(SR.Get(SRID.BindingExpressionIsDetached)); 

        if (Worker != null) 
        {
            Worker.RefreshValue();  // calls TransferValue
        }
    } 

Worker gets instance in internal override void BindingExpression.Activate(). Also inside Activate() BindingExpression.Status set to BindingStatus.Active.

How can I programmatically initiate execution for BindingExpression.Activate() and make UpdateTarget after that?

Update

Solution here (thanks, Olli):

public  void UpdateAllBindingTargets( DependencyObject obj)
    {

        FrameworkElement visualBlock = obj as FrameworkElement;
        if (visualBlock==null)
            return;
        if (visualBlock.DataContext==null)
            return;
        Object objDataContext = visualBlock.DataContext;

        IEnumerable<KeyValuePair<DependencyProperty, BindingExpression>> allElementBinding = GetAllBindings(obj);
        foreach (KeyValuePair<DependencyProperty, BindingExpression> bindingInfo in allElementBinding)
        {
            BindingOperations.ClearBinding(obj, bindingInfo.Key);

            Binding myBinding = new Binding(bindingInfo.Value.ParentBinding.Path.Path);
            myBinding.Source = objDataContext;
            visualBlock.SetBinding(bindingInfo.Key, myBinding);
            BindingOperations.GetBindingExpression(visualBlock, bindingInfo.Key).UpdateTarget();

        }

    }

where getting all bindings for object:

public  IEnumerable<KeyValuePair<DependencyProperty, BindingExpression>> GetAllBindings( DependencyObject obj)
    {
        var stack = new Stack<DependencyObject>();

        stack.Push(obj);

        while (stack.Count > 0)
        {
            var cur = stack.Pop();
            var lve = cur.GetLocalValueEnumerator();

            while (lve.MoveNext())
                if (BindingOperations.IsDataBound(cur, lve.Current.Property))
                {
                    KeyValuePair<DependencyProperty,BindingExpression> result=new KeyValuePair<DependencyProperty, BindingExpression>(lve.Current.Property,lve.Current.Value as BindingExpression);
                    yield return result;
                }

            int count = VisualTreeHelper.GetChildrenCount(cur);
            for (int i = 0; i < count; ++i)
            {
                var child = VisualTreeHelper.GetChild(cur, i);
                if (child is FrameworkElement)
                    stack.Push(child);
            }
        }
    }
  • 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-12T22:11:30+00:00Added an answer on June 12, 2026 at 10:11 pm

    You can programmatically create a new binding, which should do the trick.

    http://msdn.microsoft.com/en-us/library/ms752347.aspx#creating_a_binding

    Example from the MSDN page

    MyData myDataObject = new MyData(DateTime.Now);      
    Binding myBinding = new Binding("MyDataProperty");
    myBinding.Source = myDataObject;
    myText.SetBinding(TextBlock.TextProperty, myBinding);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have various important variables that I need transfering from PHP to JS on
I am remotely transfering the files into linux box from windows via batch script
I'm using WCF services in the client application for transfering data from client to
Upon transfering my site from one server to another, some functions started behaving differently.
Is transfering a file from the desktop to an iPhone quicker than downloading the
I am transfering data from an old database to a new one, and I
I am processing a big .gz file using PHP (transfering data from gz to
We are transfering our code from C++ to C# and due to limited knowledge
What is the proper way for transfering complex objects from iOS app to Unity3D
I'm currently transfering some source code from a Subversion (SVN) repository to my client's

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.