Create Expander dynamically

6 posts, 0 answers
  1. Steve
    Steve avatar
    1 posts
    Member since:
    Oct 2010

    Posted 30 Oct 2010 Link to this post

    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

  2. Miro Miroslavov
    Miro Miroslavov avatar
    588 posts

    Posted 04 Nov 2010 Link to this post

    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.

    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
  3. Rajat Barik
    Rajat Barik avatar
    2 posts
    Member since:
    Oct 2012

    Posted 10 May 2012 Link to this post


    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
  4. Roger
    Roger avatar
    1 posts
    Member since:
    May 2012

    Posted 12 May 2012 Link to this post

    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

  5. Michael
    Michael avatar
    1 posts
    Member since:
    Jan 2012

    Posted 12 May 2012 Link to this post

    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.

  6. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 15 May 2012 Link to this post

    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.

    Tina Stancheva
    the Telerik team

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

Back to Top