none
Accordion - getting the list of children from the collection

    Question

  •  I've got a simple problem here.

     I have an accordion that's populated within xaml (i.e. isn't not dynamic) and contains mulitple buttons under each accordion item.

     It looks something like this:

    > ITEM 1

    > ITEM 2

    > ITEM 3

    \/ ITEM 4

        BUTTON 1

        BUTTON 2

        BUTTON 3

     

     Hopefully that makes sense. I can find out the selected item easily enough:

      

    Private Sub myAccordion_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs) Handles myAccordion.SelectionChanged
    
            Dim myString as String
    
            For Each SelectedAccordionItem As AccordionItem In e.AddedItems
              myString = SelectedAccordionItem.Header
            Next SelectedAccordionItem
    
    End Sub

     

    This would set myString to "ITEM 4". But what I'm really after is a list of the buttons that are under this selected item (BUTTON 1, BUTTON 2, and BUTTON 3).

    How can I do this?

    Wednesday, January 27, 2010 10:37 PM

Answers

  •  You need to access the Content of the Accordion SelectedItem :

     XAML:

            <layoutToolkit:Accordion
                x:Name="accordion1"
                SelectionChanged="accordion1_SelectionChanged">
                <layoutToolkit:AccordionItem
                    Header="Item-1"
                    Content="Item-1 Content.." />
                <layoutToolkit:AccordionItem
                    Header="Item-2">
                    <layoutToolkit:AccordionItem.Content>
                        <StackPanel>
                            <Button
                                Content="Button1"></Button>
                            <Button
                                Content="Button2"></Button>
                            <Button
                                Content="Button3"></Button>
                        </StackPanel>
                    </layoutToolkit:AccordionItem.Content>
                </layoutToolkit:AccordionItem>
            </layoutToolkit:Accordion>
     XAML.cs:
            private void accordion1_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var myAccordion = sender as Accordion;
                var selectedItem = myAccordion.SelectedItem as AccordionItem;
                var selectedItemContent = selectedItem.Content;
    
                var sp= selectedItemContent as StackPanel;
    
                if (sp!=null)
                {
                    var butttons = sp.Children
                        .Where(w => w.GetType().Equals(typeof(Button)))
                        .Select(s => s as Button)
                        .ToList();
                }
    
            }
     
    Thursday, January 28, 2010 2:24 AM