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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:31:08+00:00 2026-05-23T21:31:08+00:00

Perhaps hoping in a miracle, but let’s try :-) MyControl derives from Control. Its

  • 0

Perhaps hoping in a miracle, but let’s try 🙂

MyControl derives from Control. Its ControlTemplate contains

<ContentPresenter ContentTemplate="{TemplateBinding EditorTemplate}"/>

(Other details are omitted.)

Derived controls supply suitable EditorTemplate. For example MyTextControl specifies template consisting of a TextBox. (With proper bindings, of course.)

I won’t describe what works (most scenarios), but what does not:

A collapsed MyTextControl instance is created. Later on this control is made visible. Here is what happens:

  • MyTextControl instance created, set to Collapsed
  • MyTextControl.Loaded event: At this moment the visual tree contains MyTextControl with no children.
  • In the Loaded handler I call ApplyTemplate(). In turn the visual tree is modified to MyTextControl -> ContentPresenter. That’s all, no more children.
  • Stil in Loaded handler, I assign Loaded handler to the ContentPresenter.
  • Sometimes later the control is made visible. Its visual tree gets populated by TextBox internals: Border -> ContentControl -> ContentPresenter -> internal TextBoxView. In other words the control just works.

The problem is that the ContentPresenter Loaded handler was not called, i.e. I am not able to identify the moment when the control is ready.

I tried an alternative solution, i.e. instead of forcing ApplyTemplate() I simply waited in MyControl.OnApplyTemplate(). The sequence:

  • MyTextControl instance created, set to Collapsed
  • In the Loaded handler the visual tree contains MyTextControl with no children.
  • The control is made visible.
  • In OnApplyTemplate() the visual tree is MyTextControl->ContentPresenter.
  • Stil in OnApplyTemplate(), I assign Loaded handler to the ContentPresenter.
  • The rest is as before. The visual tree is populated by TextBox internals (the control works), but the above handler gets not called.

Does anybody know a way how to identify the moment when the control is fully loaded?

Note that I did the above with several other MyControl-derived controls. For each of them one of the above scenarios worked (sometimes one, sometimes another), but the TextBox-based control is the first one where I am not able to identify moment of loading.

Also note that this problem does not happen when the control is visible for all the time.

  • 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-23T21:31:09+00:00Added an answer on May 23, 2026 at 9:31 pm

    Ok, I’ll answer myself. My current conclusion after 1 day and dozens of tests is that Loaded event is for birds. It happens on various stages of the control life cycle and in case of composite controls there is no warranty that the control is fully functional. In some cases it might be not fired at all.

    Forcing template building by calling ApplyTemplate() is no solution either as in some cases it may result in building partial control tree.

    OnApplyTemplate suffers similar problems – it might be called when only partial control tree is built.

    After acknowledging the above statements I decided to give a try to LayoutUpdated event. I set up the handler in OnApplyTemplate() (I tried to use latest possible moment) and investigated the control tree. As a first approximation it seems to be sufficient to check if the ContentPresenter has children. If so, we’ll say that the control is loaded and unregister LayoutUpdated handler. A more sofisticated test could be used, but the trivial one I just described is working for wide range of controls.

    Originally I was afraid that the LayoutUpdated solution will be inefficient, but it looks like (using the described organization) the first handler call is exactly the place when the control is “loaded”.

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

Sidebar

Related Questions

Idle pondering from a Scala learner perhaps, but ... in my tinkerings I've written
Was hoping someone could point me in the right direction, perhaps to a tutorial
I've tried reading the documentation but it is rather impenetrable so I'm hoping someone
Has anyone tried migrating from ScrewTurn to Confluence ? I'm hoping that I can
first post here, hoping someone could perhaps shed some light on an issue I've
I was hoping to use groovy's invokeMethod to do this, but it turns out
I'm perhaps overlooking something, but I'm attempting to wrestle protocol buffers into an easy
This may be a pipe dream, but I'm hoping someone knows of a tool
Have seen some conversations revolving around this, but hoping for some current input as
I'm almost certain I know the answer to this question, but I'm hoping there'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.