Windows Phone 7.1 - Xaml Get-Item Component

This WP7.1 XamlHelper assembly is used to retrieve visual-items from collections generated using data-templates, using .Net ItemContainerGenerator method.

This is another new WP7.1 assembly used to help ease development on Windows Phone. I will be adding additional WP7.1 assemblies in the near future.

I use a default namespace string for all helper assemblies, making it easier to organize and locate assemblies within projects. Each helper assembly will be marked with the following default namespace: "BenScharbach.WP7.Helpers", with the actual namespace's specific name at the end of the default namespace; for example, 'Xaml.GetItem' for this assembly.

The Xaml Get-Item assembly is used to locate some UiElement located within an ItemsControl. For example, the UiElement might be a TextBlock named MyTextBlock which is located in a DataTemplate. To complicate the visual-tree search, the DataTemplate might be stored in the Resources section of some other xaml item, like the Grid. Using the FindCollectionVisualItem{tcompare}() method allows searching for this UiElement by name within the generated collections, which can included Templates stored as static resources.

To use this assembly, simply reference my static class helper using the built-in static methods. Currently, my static class helper contains only 2 methods, with 1 overload method;

  1. FindCollectionVisualItem{tcompare}(ItemsControl, object, string)
  2. FindCollectionVisualItem{tcompare}(ItemsControl, index, string) = OVERLOAD Method
  3. FindVisualItem{tcompare}((DependencyObject, string)

As a side note, my helper uses the .Net VisualTreeHelper class in a recursive method call to locate UiElements. Furthermore, my helper uses the ItemsControl's ItemContainerGenerator() method call in order to locate generated items.

For more information on generated items, see the following website which I used as reference for my assembly;

Ben Scharbach