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

How to get dynamic controls from RadExpander

2 Answers 81 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sreedevi
Top achievements
Rank 1
Sreedevi asked on 08 Dec 2011, 04:53 PM
Hi,

We are using Radexpander control,while loading expander inernally we are adding some controls(Textboxes,Combobx.........).here i want to get the all controls  which are available in the Radexpander .please guide me to resolve this.it's very very urgent for me.


Thanks,
-Sree

2 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 13 Dec 2011, 01:53 PM
Hello Sreedevi,

You can find the content of the RadExpander through its Content property. It will return the root control used as a content of the control. Then you can traverse through the children of this item and so on until you get all UIElements used in the RadExpander.Content.

For example:
private void AddContent(RadExpander expander)
{
    expander.Header = "MyExpander";
 
    StackPanel panel = new StackPanel();
 
    TextBlock txt = new TextBlock { Text="TextBlock 1"};
    panel.Children.Add(txt);
 
    RadComboBox combo = new RadComboBox();
    combo.Items.Add(new RadComboBoxItem { Content = "Item 1" });
    combo.Items.Add(new RadComboBoxItem { Content = "Item 2" });
    combo.Items.Add(new RadComboBoxItem { Content = "Item 3" });
    panel.Children.Add(combo);
 
    expander.Content = panel;
}
 
private void GetContent(RadExpander expander)
{
    string header = expander.Header.ToString();
 
    StackPanel panel = expander.Content as StackPanel;
    if (panel != null)
    {
        foreach (var item in panel.Children)
        {
            //get the UIElements declared in the RadExpander.Content
        }
    }
             
}

Is this what you were looking for or am I missing something?

Best wishes,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Tina Stancheva
Telerik team
answered on 16 Dec 2011, 03:42 PM
Hello Sreedevi,

I wanted to follow up on your question, as we received a similar mail, I believe it might be from a collegue of yours. The mail pointed me to teh fact that you're trying to get the Content of the RadExpander in the context of TestStudio.

This is why I wanted to let you know that in TestStudio you can get the content of the RadExpander control through a ContentPresenter. Basically when you try to access the RadControls for Silverlight using Test Studio, you'll have to follow the structure of the VisualTree as the TestStudio will give you access to those elements. Having this in mind, you can get the RadExpander header element through a RadToggleButton and its Content through a ContentPreseneter. However, the content of the ContentPresenter will depend on the visual tree structure that you build in the definition of the control.

Also, if you can elaborate on the scenario you need to implement - why you need to access the content of the RadExpander, we will be able to better assist you and we might be able to suggest you different approaches.

Best wishes,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
General Discussions
Asked by
Sreedevi
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or