Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
Hi,

I'm using Silverlight 4 and VS 2010.

I have a StackPanel with a ItemsControl.
It's ItemTemplate is binded to it's respective DataTemplate.
It is filled with a few Expanders with a lot of data in each one.
Whenever I expand one of these Expanders I want to collapse all the remaining Expanders.

On another part of my project I have a similar structure where the Expanders are hard coded.
To achieve the same result I just go through the StackPanel.Children collection with a foreach cicle and collapse all the Expanders.

Using a Stackpanel and an ItemsControl I can't do that because the Itemscontrol is the only child on the Stackpanel.Children.

Can anyone help on how do I get to each of the Expanders using c# code behind and collapse them?

HTML
<DataTemplate x:Key="AvaliacaoDataTemplate">
   <Grid>
      <toolkit:Expander x:Name="ExpanderAvaliacao" Header="{Binding}" d:LayoutOverrides="Width, Height" HeaderTemplate="{StaticResource AvaliacaoDataTemplateHeader}" Style="{StaticResource StyleExpanderBlue3}" Expanded="Expander_Expanded">
         <StackPanel>
            <!-- Lots of stuff -->
         </StackPanel>
      </toolkit:Expander>
   </Grid>
</DataTemplate>


<StackPanel x:Name="Avaliacoes">
   <ItemsControl x:Name="ItemsAvaliacao" ItemTemplate="{StaticResource AvaliacaoDataTemplate}"/>
</StackPanel>


I really need some light on this issue!
Anyone?!!


Thanks.
Posted
Updated 11-May-12 1:14am
v3

1 solution

Found the answer myself and posted as an Article in here.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900