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

RadBook PageFilpEventArgs.Page.FindName

2 Answers 59 Views
Book
This is a migrated thread and some comments may be shown as answers.
John Thompson
Top achievements
Rank 2
John Thompson asked on 02 Mar 2010, 02:47 PM
I have the follow XAML in a RadBook control and I am attempting to find a control in the Grid.

            <telerikNavigation:RadBook.LeftPageTemplate> 
                <DataTemplate> 
                    <Border BorderBrush="Silver" BorderThickness="2"
                        <Grid x:Name="PageRoot" Background="GhostWhite"
                            <Grid.RowDefinitions> 
                                <RowDefinition Height="Auto"/> 
                                <RowDefinition Height="*"/> 
                                <RowDefinition Height="Auto"/> 
                            </Grid.RowDefinitions> 
 
                            <Border Background="LightGray" Opacity="0.5" BorderThickness="0 0 0 1" BorderBrush="Gray"
                                <TextBlock Text="{Binding FullName}" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" TextWrapping="Wrap" /> 
                            </Border> 
 
                            <Image Source="{Binding Photograph, Converter={StaticResource convertImage}}" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Stretch="None" Opacity="1" /> 
 
                            <TextBlock x:Name="EmpNo" Text="{Binding EmployeeNumber}" HorizontalAlignment="Center" Grid.Row="2" VerticalAlignment="Center" FontSize="12" FontWeight="Bold" TextWrapping="Wrap" Tag="{Binding EEID}" /> 
                        </Grid> 
                    </Border> 
                </DataTemplate> 
            </telerikNavigation:RadBook.LeftPageTemplate> 

            TextBlock empNo = e.Page.FindName("PageRoot") as TextBlock; 



The empNo instance is always null and of course EmpNo is not defined because it is inside a DataTemplate control.  Is there anyway to access the TextBlock either in code or declaratively.  Thank you in advance!

2 Answers, 1 is accepted

Sort by
0
Helen
Top achievements
Rank 2
answered on 03 Mar 2010, 11:42 PM
0
Kiril Stanoev
Telerik team
answered on 04 Mar 2010, 08:22 AM
Hi John,

WPF's DataTemplate has a nice method called FindName, which unfortunately is missing in Silverlight. Therefore, for this scenario you will have to use the VisualTreeHelper class:

private void Book_PageFlipStarted(object sender, PageFlipEventArgs e)
{
    Grid bookItemLayoutRoot = VisualTreeHelper.GetChild(e.Page, 0) as Grid;
    ContentPresenter contentPresenter = (bookItemLayoutRoot as Grid).Children[0] as ContentPresenter;
    Border pageRoot = VisualTreeHelper.GetChild(contentPresenter, 0) as Border;
    TextBlock empNo = pageRoot.FindName("EmpNo") as TextBlock;
}

Give it a try and let me know if it helps.

Greetings,
Kiril Stanoev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Book
Asked by
John Thompson
Top achievements
Rank 2
Answers by
Helen
Top achievements
Rank 2
Kiril Stanoev
Telerik team
Share this question
or