This is a migrated thread and some comments may be shown as answers.

Enumarating elements on an expander

1 Answer 43 Views
Expander
This is a migrated thread and some comments may be shown as answers.
HDC
Top achievements
Rank 1
HDC asked on 14 Dec 2010, 12:31 PM
Hi,

I have placed a large number of controls inside a grid on a RadExpander control.

I would like to loop on all the child controls that i have in the RadExpander and hook up event handlers on the controls found. I know the VisualTreeHelper is supposed to do the job but for some reason however the controls are never getting hooked up.

This is my code... PropPanel is a stackpanel that contains all of the expander controls, i am using a stack object to avoid recursivity

 

Stack<FrameworkElement> visualstack = new Stack<FrameworkElement>();
  
            visualstack.Push(PropPanel);
  
            while (visualstack.Count > 0)
            {
                FrameworkElement child = visualstack.Pop();
                  
                int count = VisualTreeHelper.GetChildrenCount(child);
                  
                for (int cnt = 0; cnt < count; cnt++)
                {
                    FrameworkElement el = (FrameworkElement)VisualTreeHelper.GetChild(child, cnt);
                      
                    if (el is tc.RadNumericUpDown)
                        ((tc.RadNumericUpDown)el).ValueChanged += PropertyPanelValueChanged;
                    else if (el is TextBox)
                        ((TextBox)el).TextChanged += PropertyPanelTextChanged;
                    else if (el is tc.RadColorPicker)
                        ((tc.RadColorPicker)el).SelectedColorChanged += PropertyPanelSelectedColorChanged;
                    else if (el is ComboBox)
                        ((ComboBox)el).SelectionChanged += PropertyPanelComboSelectionChanged;
                    else if (el is Button && !(el is CheckBox))
                        ((Button)el).Click += PropertyPanelButtonClick;
                    else if (el is ToggleButton && !(el is CheckBox))
                        ((ToggleButton)el).Click += PropertyPanelToggleButtonClick;
                    else if (el is CheckBox)
                    {
                        ((CheckBox)el).Checked += PropertyPanelChecked;
                        ((CheckBox)el).Unchecked += PropertyPanelChecked;
                    }
                    else                    
                        visualstack.Push(el);
                }
            }

 

 

 

Can anyone tell me what i'm missing, why are the controls notbeing hooked up?

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 16 Dec 2010, 04:25 PM
Hi Peter,

I was not able to reproduce the issue you're describing. Could you please take a look at the attached project and let me know if I am missing something. I'd be glad to further assist you.

Regards,
Kiril Stanoev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Expander
Asked by
HDC
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question
or