Enumarating elements on an expander

2 posts, 0 answers
  1. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 14 Dec 2010 Link to this post

    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?

     

     

     

     

  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 16 Dec 2010 Link to this post

    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
  3. DevCraft banner
Back to Top