views:

29

answers:

1

I have an ItemsControl:

<StackPanel>
    <ItemsControl x:Name="TopicList">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <local:TopicListItem Title="{Binding Title}" LocationCloud="{Binding Locations}" TagCloudData="{Binding TagCloudData}" SparklineData="{Binding SparklineData}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>

Then I get some XML and turn that into an IEnumerable<ListObj> using LINQ which is then attached to TopicList.ItemsSource. As you see the only element in the list is a UseControl that I made myself called TopicListItem. I want to be able to access the index of items that the ItemsControl has from the TopicListItem.xaml.cs file so that as I click on one of them to perform an open action, I can close the rest.

Thanks for the help :)

(and I have tried Accordion and AccordionItems, to stiff for my taste :D )

A: 

I'll answer it myself since I got some help within the company.

The way I did it was to simply access the ItemsControl elemement and get the collection from the Items property.

MainPage root = Application.Current.RootVisual as MainPage;
foreach(MyClass c in root.TopicList.Items) 
{
    // loop through them all and close/open conditionally
}

I hope this help anyone else.

WmasterJ