Skip to main content

Microsoft Silverlight

Unanswered Question Data binding events and accessing UI elements that are dynamically generated based on templates and data bindingRSS Feed

(0)

lm_telrex
lm_telrex

Member

Member

0 points

3 Posts

Data binding events and accessing UI elements that are dynamically generated based on templates and data binding

 

I have a few questions regarding data binding and accessing the UI elements that are dynamically generated as a result. Once in a while I have the need to access such elements to do things that cannot be done with just data binding. For example I need to place the focus on a specific element in a list that is generated based on templates and data binding. Here are my questions: 
  1. Are there any events that are fired while templated elements are being created?
  2. I need to know when the dynamic generation of UI elements is done. Is there a way?
    For example I have a list that is generated via templates and data binding. I need to place the focus on a specific element in that list. I found a way to access the UI Element corresponding to the item I am targeting but I cannot do so immediately after I trigger the data binding since at that point the UI element are not yet created. What I do now is to use something like: Dispatcher.BeginInvoke( () => SetFocusOnTargetElement((…))
    However I am not sure if this is 100% reliable. I am afraid that Dispatcher.BeginInvoke will call SetFocusOnTargetElement before all elements of by list were generated. 
     
  3. Related to the previous question. I know that for a scenario where UI elements are generated based on data binding, the system generates the UI elements asynchronously. How long does that take? If I trigger the data binding and then call Dispatcher.BeginInvoke( () => DoSomething((…)) will DoSomething be invoked after all the UI elements were generated? Or that is not guaranteed and I may have DoSomething invoked before all the UI elements were generated?

Thanks

 

msalsbery
msalsbery

Contributor

Contributor

2066 points

379 Posts

Re: Data binding events and accessing UI elements that are dynamically generated based on templates and data binding

For elements created via a template, you may want to take a look at the OnApplyTemplate method.

For question 3, I personally would be extremely hesitant to rely on any kind of FIFO nature with the dispatcher queue, unless I saw documentation stating it could be relied on.  I choose to design so I don't have to rely on something like that.


Mark Salsbery
Microsoft MVP - Visual C++
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities