RadBook PageFilpEventArgs.Page.FindName

3 posts, 0 answers
  1. John Thompson
    John Thompson avatar
    44 posts
    Member since:
    Dec 2009

    Posted 02 Mar 2010 Link to this post

    I have the follow XAML in a RadBook control and I am attempting to find a control in the Grid.

                        <Border BorderBrush="Silver" BorderThickness="2"
                            <Grid x:Name="PageRoot" Background="GhostWhite"
                                    <RowDefinition Height="Auto"/> 
                                    <RowDefinition Height="*"/> 
                                    <RowDefinition Height="Auto"/> 
                                <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" /> 
                                <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}" /> 

                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. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 03 Mar 2010 Link to this post

  3. Kiril Stanoev
    Kiril Stanoev avatar
    1512 posts

    Posted 04 Mar 2010 Link to this post

    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.

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