Navigate to specific page from code behind

5 posts, 1 answers
  1. Paul
    Paul avatar
    11 posts
    Member since:
    May 2009

    Posted 15 Feb 2011 Link to this post

    Hi,
    Is there a way to navigate a book to a specific page from code behind?  I want to create a table of content besides the book that the user could also use for navigation just like the attached image
    Thanks,
    Paul
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Feb 2011 Link to this post

    Hello Paul,

    A possible approach could be seen in this demo. You can examine its code. The table of contents is realized with RadTreeView and basically it uses the Tag property for navigation. Feel free to ask if you need more info on this.

    Greetings,
    Petar Mladenov
    the Telerik team
  3. DevCraft banner
  4. Paul
    Paul avatar
    11 posts
    Member since:
    May 2009

    Posted 18 Feb 2011 Link to this post

    Hi Petar,

    That seems like a good approach.  Can you elaborate on the use of the TAG property.  I do no see any method in the RadBook that permits navigation using the Tag property (i.e.: something like myBook.GoToTag("mytag")).

    Paul
  5. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Feb 2011 Link to this post

    Hi Paul,

    You can examine the source code of the example by clicking the "ViewCode" button.
    In the XAML part of the application you can see that different RadTreeViewItems that specify the contents of the book, have their Tag property set:
    <telerik:RadTreeView Margin="25,45,25,0" x:Name="RadTreeView1">
                        <telerik:RadTreeViewItem Tag="4" Header="UI Components"
                                IsExpanded="True">
                            <telerik:RadTreeViewItem Cursor="Hand"
                                    DefaultImageSrc="../Images/Book/Icons/aspnet.png" Header="ASP.NET Ajax" />
                            <telerik:RadTreeViewItem Cursor="Hand"
                                    DefaultImageSrc="../Images/Book/Icons/Sl.png" Header="Silverlight" />
                            <telerik:RadTreeViewItem Cursor="Hand"
                                    DefaultImageSrc="../Images/Book/Icons/mvc.png" Header="ASP.NET MVC" />
                            <telerik:RadTreeViewItem Cursor="Hand"
                                    DefaultImageSrc="../Images/Book/Icons/winforms.png" Header="Winforms" />
                            <telerik:RadTreeViewItem Cursor="Hand"
                                    DefaultImageSrc="../Images/Book/Icons/wpf.png" Header="WPF" />
                        </telerik:RadTreeViewItem>
                        <telerik:RadTreeViewItem Header="Data" Tag="6" IsExpanded="True">
                            <telerik:RadTreeViewItem Cursor="Hand"
    Then, in code behind , we parse the Tag into int (pageindex) and navigate to the Page corresponding to the parsed pageindex:
    void RadTreeViewItem_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                if (this.foldActivated)
                {
                    return;
                }
      
                RadTreeViewItem item = (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>();
                if (item == null) return;
      
                object tag = (item.Parent as FrameworkElement).Tag;
                if (tag == null) return;
      
                int pageIndex = Int16.Parse(tag.ToString());
                if (pageIndex > 0)
                {
                    RadBook1.RightPageIndex = pageIndex;
                }
            }
    Hope this has helped you.

    Greetings,
    Petar Mladenov
    the Telerik team
  6. Paul
    Paul avatar
    11 posts
    Member since:
    May 2009

    Posted 18 Feb 2011 Link to this post

    Hi Petar,
    Yes, that helps.
    Thanks,
    Paul
Back to Top
DevCraft banner