Diagram notify on Render Complete

1 Answer 53 Views
Diagram
Mrugendra
Top achievements
Rank 1
Iron
Mrugendra asked on 10 May 2022, 06:26 AM

Hi,

We are building a template system using Telerik WPF Diagram.  This involves replacing template shape content with actual data from the DB. Based on the data, we have to move shapes around in relation to each other.   

Now, the issue is that for shapes that have width set to Auto, you can not get the shape dimensions before the shape  is rendered by the diagram, and there does not seem to be any event that indicates whether the diagram has done rendering all the items that have been added to it programmatically.  

Random Thread.sleep is problematic as you can imagine. Is there any solid mechanism available wherein one can know that the diagram has completed the rendering the final item that has been added to it?

We basically need a event/callback that will be triggered once the diagram has completed rendering of items. 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 12 May 2022, 08:56 AM

Hello Mrugendra,

There is no such event. This is mostly because the WPF framework doesn't provide this type of API. Usually, the most reliable approach that can be used to determine if the corresponding UI element was already measured properly is to wait a bit after it has been added to the UI and then check its values. For example, you can subscribe to its Loaded event and use a Dispatcher to delay the corresponding operation a bit. Or alternatively, you can subscribe to SizeChanged and wait for the proper size.

In your case you can try the ItemsChanged event of RadDiagram. The event is fired whenever you add or remove items. In case you add a shape, you can dispatch the action that gets the shape's actual size (with Dispatcher.BeginInvoke). 

I hope this information helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Mrugendra
Top achievements
Rank 1
Iron
commented on 12 May 2022, 09:22 AM

Hi Martin,

Thank you for the reply.

We achieved it more or less in the way you suggested it.   

=> First of all, the code that added items to the diagram had to be inside an async method, this ensured that the UI thread was available to render the items in the diagram that were added programmatically.   If you don't do this, no matter how long you wait,  your are waiting the main thread, nothing gets rendered.

=> Then, we waited for the last item's IsLoaded property in order to make sure the diagram had rendered it.  The wait was achieved using Task.Delay method instead of the Thread.sleep method.

Thank you again for your time. 

 

Martin Ivanov
Telerik team
commented on 12 May 2022, 09:23 AM

Thank you for sharing your solution.
Tags
Diagram
Asked by
Mrugendra
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or