Xaml Get-Item

Windows Phone 7.1



The Windows Phone 7.1 xaml-get-item helper is used to retrieve visual-items from collections generated using data-templates, with .Net ItemContainerGenerator() method.

The xaml-get-item helper is used to locate some UI element located within an items-control. As an example, the UI element might be a text-block named "MyTextBlock" which is located in a data-template. To complicate the visual-tree search, the data-template might be stored in the resources section of some other xaml item; like the grid. Using the FindCollectionVisualItem{tcompare}() method allows searching for this UI element by name within the generated collections, which can include templates stored as static resources.

To use this helper, consuming code calls the static class using the built-in static methods. The static class contains only two methods, with one overload method;

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


Note: The xaml-get-item helper uses the .Net VisualTreeHelper class in a recursive method call to locate UI elements. Also, the helper uses the ItemsControl.ItemContainerGenerator() method call in order to locate generated items.

For more information on generated items;
http://stackoverflow.com/questions/16375375/how-do-i-access-a-control-inside-a-xaml-datatemplate.