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

Get The instance of StackPanel in above mentioned code

4 Answers 78 Views
Docking
This is a migrated thread and some comments may be shown as answers.
gautham
Top achievements
Rank 1
gautham asked on 22 Oct 2009, 05:12 AM
Hello I tried your code, but in the starting stage itself code fail. 
  by returning zero "int count = System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent);"  
  Here, I am providing full structure of my code 
  
<Grid x:Name="uxMainGrid" Height="470" Width="1000"
        <Grid.Resources> 
            <ControlTemplate x:Name="uxContentControlWithFooterControlTemplate" x:Key="ContentControlWithFooterControlTemplate" 
                              TargetType="ContentControl"
                <Grid> 
                    <Grid.RowDefinitions> 
                        <RowDefinition Height="*"/> 
                        <RowDefinition Height="30"/> 
                    </Grid.RowDefinitions> 
                    <ContentPresenter x:Name="uxContentControlWithFooterControlPresenter"  Content="{TemplateBinding Content}" Grid.Row="0" /> 
                    <StackPanel x:Name="uxFlightEntryDisplayfooterStackPanel" Background="Red" Orientation="Vertical"  Grid.Row="1"
                        <TextBlock x:Name="uxFlightEntryDisplayfooter"  Text="{Binding FlightEntryDisplayfooter}" TextWrapping="Wrap"/> 
                    </StackPanel> 
                </Grid> 
  
            </ControlTemplate> 
        </Grid.Resources> 
  
        <Grid.RowDefinitions> 
            <RowDefinition Height="5" /> 
            <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
        <telerikDocking:RadDocking  Grid.Row="1"
            <telerikDocking:RadSplitContainer  ScrollViewer.HorizontalScrollBarVisibility="Auto" Orientation="Vertical" InitialPosition="DockedLeft"  Height="400"  Width="980"
                <telerikDocking:RadPaneGroup   telerikDocking:ProportionalStackPanel.RelativeSize="40, 40"
                    <telerikDocking:RadPane x:Name="uxSchedule"   Header="Schedule" Title="{Binding FlightEntryDisplayheader, Mode=TwoWay}"
                        <ContentControl Template="{StaticResource ContentControlWithFooterControlTemplate}" x:Name="uxContentControlWithFooterTelerikControlTemplate"
                           <data:DataGrid> 
                            </data:DataGrid> 
                        </ContentControl> 
                    </telerikDocking:RadPane> 
                </telerikDocking:RadPaneGroup> 
                 
                 
            </telerikDocking:RadSplitContainer> 
        </telerikDocking:RadDocking> 
    </Grid> 
 

4 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 22 Oct 2009, 11:23 AM
Hello Gautham,

Could you please give more details about what you want to achieve and what code did you use for that.

Regards,
Miroslav Nedyalkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
gautham
Top achievements
Rank 1
answered on 23 Oct 2009, 04:57 AM
Hello,

         In order to write Test code.
 StackPanel sp2 = null
            this.GetStackPanel(this.view.uxContentControlWithFooterTelerikControlTemplate, ref sp2); 
 
            var sp1sp1TextBox = sp1.Children.Where(w => w.GetType().Equals(typeof(TextBlock))).Select(s => s as TextBlock).SingleOrDefault(); 
 
 
 private void GetStackPanel(UIElement parent, ref StackPanel st) 
        { 
            int count = VisualTreeHelper.GetChildrenCount(parent); 
            if (count > 0) 
            { 
                for (int i = 0; i < count; i++) 
                { 
                    var child = (FrameworkElement)VisualTreeHelper.GetChild(parent, i); 
                    if (child != null && child.Name.Equals("uxFlightEntryDisplayfooterStackPanel")) 
                    { 
                        st = child as StackPanel; 
                        return; 
                    } 
                    GetStackPanel(child, ref st); 
                } 
            } 
        } 
 
0
Miroslav Nedyalkov
Telerik team
answered on 23 Oct 2009, 08:33 AM
Hi Gautham,

It sounds like the template of the ContentControl is not applied when you code is called. Because of that the SplitContainer is not created yet and it is not in the visual tree. What I could suggest you is to call the code after the ContentControl is loaded (hook up to its Loaded event).

One more suggestion - in order to cut off some lines of code you could use one of the extension methods, that come with RadControls for Silverlight - ChildrenOfType, that is a generic method that retrieves all visual children of a specified UIElement of a specified type. Note that this extension method is meant to be used only in tests. Here is an example how to use it in your case:
StackPanel stackPanel = this.view
                    .uxContentControlWithFooterTelerikControlTemplate
                    .ChildrenOfType<StackPanel>()
                    .First(sp => sp.Name.Equals("uxFlightEntryDisplayfooterStackPanel"));
TextBlock tb = stackPanel.Children.OfType<TextBlock>().SingleOrDefault();

Sincerely yours,
Miroslav Nedyalkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
gautham
Top achievements
Rank 1
answered on 24 Oct 2009, 09:50 AM
ThankYou.
Tags
Docking
Asked by
gautham
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
gautham
Top achievements
Rank 1
Share this question
or