Expander in ListBox does not decrease size of list box

2 posts, 1 answers
  1. Philip
    Philip avatar
    9 posts
    Member since:
    Feb 2012

    Posted 27 Sep 2012 Link to this post


    I'm using the Expander in a ListBox ItemTemplate like this:





                                <ColumnDefinition Width="Auto"/>

                                <ColumnDefinition Width="*"/>


                            <telerik:RadExpander Grid.Column="0" x:Name="radExpander" VerticalAlignment="Top"



                                                 FlowDirection="RightToLeft" >








                            <telerik:RadToggleButton [...]/>




    When I expand the Expander, the size of the list box is increased, but on collapsing the Expander the size of the list box stays remains unchanged. It is only adjusted correctly when the list changes by adding or deleting an item. Is there a way to trigger the correct resizing on collapsing the Expander?

    Thanks for your help,

    Philip Thomé

  2. Answer
    Pavel R. Pavlov
    Pavel R. Pavlov avatar
    1240 posts

    Posted 01 Oct 2012 Link to this post

    Hi Philip,

    This issue is caused by the VirtualizingStackPanel which:
    • is native .NET Framework class
    • is used by our RadListBox control as the default ItemsPanel
    • does not recalculate it`s size when shrinking the height of the elements inside it, in your case when collapsing the RadExpander control

    In case you use a data binding approach, the best way to solve the issue is by using a StackPanel as an ItemsPanel. This can be done by using this code in your RadListBox:


    Please keep in mind that with this approach the virtualization of your containers is lost.(you can read more about the VirtualizingStackPanel here).

    Other way to solve the issue is to use the RadTreeView control because it has it`s own ItemsPanel which virtualizes the containers and resizes accordingly to the size of its elements.

    Kind regards,
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Back to Top