Below you will find an example that loops through the Visual Tree recursively and finds all buttons adding them to a collection. You can check the name of the button etc.. and do what you need to do. I just used a collection as an example, as I found a quick sample on it.
public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender, RoutedEventArgs e) { List<UIElement> buttons = new List<UIElement>(); GetChildren(this, typeof(Button), ref buttons); } private void GetChildren(UIElement parent, Type targetType, ref List<UIElement> children) { int count = VisualTreeHelper.GetChildrenCount(parent); if (count > 0) { for (int i = 0; i < count; i++) { UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i); if (child.GetType() == targetType) { //DO something with the button in the example added to a collection. You can also verify the name and perform the action you wish. children.Add(child); } GetChildren(child, targetType, ref children); } } }
Hope this helps