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

FindName in TabControl

1 Answer 63 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Kelley Wong
Top achievements
Rank 1
Kelley Wong asked on 15 May 2012, 04:40 AM
I create a tabcontrol which contains two tabitem
code as follows:
<Grid x:Name="LayoutRoot">
    <telerik:RadTabControl>
        <telerik:RadTabItem Header="Test1">
            <Button Content="Click"
                    Width="80"
                    Height="26"
                    x:Name="Tbtn"
                    Click="Tbtn_Click" />
        </telerik:RadTabItem>
 
        <telerik:RadTabItem Header="Test2">
            <Button Content="Click"
                    Width="80"
                    Height="26"
                    x:Name="btn"
                    Click="btn_Click" />
        </telerik:RadTabItem>
    </telerik:RadTabControl>
</Grid>


private void btn_Click(object sender, RoutedEventArgs e)
        {
            Object obj = LayoutRoot.FindName("Tbtn");
        }
 
        private void Tbtn_Click(object sender, RoutedEventArgs e)
        {
            Object obj = LayoutRoot.FindName("btn");
        }


first , the test1 tabitem is selected , i click the button to get another button in test2 tabitem,it returns well

then i selected the test2 tabitem , i click the button to get the button in test1 tabitem ,it returns null

and then i selected the test1 tabitem again , click the button ,it returns null 

what should i do if i selected the second tabitem, i want to get a control which in the first tabitem ,and suggestions?

thanks in advance

1 Answer, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 17 May 2012, 01:54 PM
Hi Kelley,

You can set the RadTabControl.IsContentPreserved property to True. You can find more info about that property here.

Kind regards,
Tina Stancheva
the Telerik team

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

Tags
TabControl
Asked by
Kelley Wong
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or