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

Expander in ListBox does not decrease size of list box

1 Answer 138 Views
Expander
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 27 Sep 2012, 08:36 AM
Hallo,



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



            <ListBox.ItemTemplate>

                <DataTemplate>

                    <Grid>

                        <Grid.ColumnDefinitions>

                            <ColumnDefinition Width="Auto"/>

                            <ColumnDefinition Width="*"/>

                        </Grid.ColumnDefinitions>

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

                              ExpandDirection="Down"

                              telerik:AnimationManager.IsAnimationEnabled="True"

                                             FlowDirection="RightToLeft" >

                            <telerik:RadExpander.Header>

       [...]

                            </telerik:RadExpander.Header>

                            <telerik:RadExpander.Content>

       [...]

                            </telerik:RadExpander.Content>

                        </telerik:RadExpander>

                        <telerik:RadToggleButton [...]/>

                    </Grid>

                </DataTemplate>

            </ListBox.ItemTemplate>



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é

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 01 Oct 2012, 02:32 PM
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:

<telerik:RadListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel/>
    </ItemsPanelTemplate>
</telerik:RadListBox.ItemsPanel>

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,
TeamX2_Pavel
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.

Tags
Expander
Asked by
Philip
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or