This is a migrated thread and some comments may be shown as answers.

Create Expander dynamically

5 Answers 135 Views
Expander
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 30 Oct 2010, 09:32 AM
I have difficulties creating Expander dynamically as requested below
         1. create multiple [RadExpander] dynamically
         2. each [RadExpander] will contain [RadWrapPanel] in the [RadExpander.Content]
         3. each [RadWrapPanel] can contain
                    a) checkbox group or
                    b) radiobutton group or
                    3) textbox  ...etc
Everything controls should be created and bound to [RadExpander] control dynamically
Can anyone help me on this? Either code snippet or sample project will be great.

Thank you
Steve


 

5 Answers, 1 is accepted

Sort by
0
Miro Miroslavov
Telerik team
answered on 04 Nov 2010, 09:32 AM
Hi Steve,

 Please find the attached example project demonstrating dynamic creation of Exanders as you wish. 
Please let me know if you have further problems.

Greetings,
Miro Miroslavov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rajat Barik
Top achievements
Rank 1
answered on 10 May 2012, 08:38 AM
Hello,

Please let me know how to bind dynamic template to the expander headers, the template should consist of one check box, one textblock and one textbox.

I want my header is having 3 columns with the three different controls. And please note that all the columns are runtime defined, there is no static columns, columns could be change at the runtime depending upon the data.

I am attaching the screen view for the expander headers. When I am creating my own such control I am getting an error : layout cycle detected.

Please let me know your inputs, weather is it possible of not, if possible show me the way to do it.

Waiting for your feedback eagerly.

With Regards,
Rajat Barik
0
Roger
Top achievements
Rank 1
answered on 12 May 2012, 06:47 AM
Hello Rajat,

It happened to me twice to waste a lot of time on this Silverlight bug. Basically, the silverlight plug-in detected a probable infinite loop resizing UI elements.

The stuff you will find on the net (StackOverFlow and Microsoft forums mostily) is that this bug is known issue related to a large number of TextBoxes (easily obtainable when you have a DataGrid or ListBox for which the ItemTemplate contains TextBoxes). However, in my case it wasn't related to TextBoxes, coincidentally, I didn't have them on the page. This may also causes may be because of many images palced inside the controls.

The fact is, I wasted a lot of time because I was looking for something I could fix in the Xaml by fixing widths and heights etc. or something more complicated than what it was actually.

Even one more case is there which I have tried with,

I have an SL page that displays a grid whose rows contain document titles, id number, doc date. It works fine as long as I am displaying no more than 123 rows. If the data contains > 123 rows then the app crashes with the subject error.

I've reviewed the various threads on this issue and they appear to be for SL3 or earlier and mostly seem to have to do with event handlers modifying layout and causing a loop. In my case it's simply a matter of how many rows are being displayed.

I have seen several posts indicating there is some "magic number" of text boxes that can be rendered, but none of these posts appear to provide any workaround.

Surely SL5, a product advertized as appropriate for "line of business applications", can handle more than 123 rows in a data grid!!

I hope this error will sortly be corrected by microsoft. And if you find any work around then dont hesitate to share.

With Regards,
Roger Ziems

0
Michael
Top achievements
Rank 1
answered on 12 May 2012, 09:21 AM

Continuing my series of gotchas for Silverlight 4, I wanted to talk about a common error that people are seeing. This error is something new that you might see when moving code from Beta 4 to the Release Candidate or later. In Beta 4, if the layout engine detected a cycle, it didn't throw any errors; as I understand it, the layout was just aborted. But with post Beta4 bits, an error is thrown.

The error you'll get will specify "Layout Cycle Detected" as the message. This error message is very accurate--the layout engine detected a cycle within your layout; or another way to say it, you have an infinite loop in your layout.

The biggest culprit that leads to this error is code within the LayoutUpdated event handler. If your LayoutUpdated event handler does anything to alter the layout of your control, then that will cause the LayoutUpdated event to fire again, and again, and again... :-)

Sometimes you need to have layout altering code within this event handler though, so what is one to do?

First, you should consider whether you really need the layout changes to occur on every call to LayoutUpdated. Would it suffice to handle the Loaded event as well as the Application.Current.Host.Content.Resized event. Between these two events, you'll get notified when the control is loaded into the visual tree, and you'll get notified any time the host is resized, which could cause you to need to change your layout again. Scenarios like modal dialogs should fall into this category.

Second, if you really do need to use LayoutUpdated, you might just need to put some conditions around your layout changes. For instance, if you are calculating a new width and height for your control, before you actually set the width and height, check to make sure the current values differ from what you calculated. This will allow the first LayoutUpdated event to resize your control, which triggers another LayoutUpdated event, but that event will recognize that there's no work to do, and the cycle will end.

These same rules will apply when you're handling the SizeChanged event, or if you're doing any other overrides on the layout of your control.
But there is a mith that the error will only occured if we using images, templates, and layout change event with heavy data.

I hope this answer will help you to find your solution.

0
Tina Stancheva
Telerik team
answered on 15 May 2012, 09:07 AM
Hi guys,

@ Michael and Roger - thank you for your valuable input and sharing your experience. I am sure the community will highly appreciate it.
@ Rajat - Even though there are 'Layout cycle detected' issues in Silverlight, we can try and change your approach in order to workaround them. Actually in a basic scenario I wasn't able to reproduce the exception, so I'm attaching a sample project demonstrating how you can go about implementing your requirements. Please have a look at it and let me know if it works for you or if your scenario requires a different approach.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Expander
Asked by
Steve
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
Rajat Barik
Top achievements
Rank 1
Roger
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or