none
DocumentViewer.MasterPageNumber why is this not working?

    Question

  • here is my form and code

    to run this, set a reference to ReachFramework, and have a xps file named "sample.xps" in the exe folder

    if u goto another page by clicking any of the first, last, next, previous, or goto buttons it does not show the correct page #, it will show the page # where the document was before the move. i even added the PageViewsChanged event for good measure, and it still doesn't show the correct page. they all execute this code     lblPage.Content = dv.MasterPageNumber which is supposed to give u the right page number. it doesn't.

    if after the page changed in the viewer u click on the "Show Current Page" button it will show the right page.

    this is driving me nuts. how do i get the correct page number to show up after a page change? help

     

    my form
    -----------------------

    <Window
      x:Class="MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow"
      WindowState="Maximized">
      <StackPanel Orientation="Vertical">
        <DocumentViewer
          Name="dv">
         
        </DocumentViewer>
          <StackPanel Orientation="Horizontal">
          <Label>Current Page  </Label>
          <Label Name="lblPage">_</Label>
          <Button Name="btnFirstPage">First</Button>
          <Button
            Name="btnLastPage">Last</Button>
          <Button
            Name="btnNextPage">Next</Button>
          <Button
            Name="btnPreviousPage">Previous</Button>
          <Button
            Name="btnGotoPage">Goto</Button>
          <TextBox
            Name="tbGotoPage">    </TextBox>
            <Button
            Name="btnShowcurrentPage">Show Current Page</Button>
        </StackPanel>

      </StackPanel>
    </Window>
    ------------------------

    my code
    ---------------------------------

    Option Strict Off
    Imports System.Windows.Xps.Packaging

    Class MainWindow

      Sub ShowCurrentPageNumber()
        lblPage.Content = dv.MasterPageNumber
      End Sub

      Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        Dim xpsDocument As XpsDocument = New XpsDocument("sample.xps", System.IO.FileAccess.Read)
        dv.Document = xpsDocument.GetFixedDocumentSequence
        ShowCurrentPageNumber()
      End Sub



      Private Sub btnFirstPage_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnFirstPage.Click
        dv.FirstPage()
        ShowCurrentPageNumber()
      End Sub

      Private Sub btnLastPage_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLastPage.Click
        dv.LastPage()
        ShowCurrentPageNumber()
      End Sub

      Private Sub btnNextPage_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnNextPage.Click
        dv.NextPage()
        ShowCurrentPageNumber()
      End Sub

      Private Sub btnPreviousPage_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnPreviousPage.Click
        dv.PreviousPage()
        ShowCurrentPageNumber()
      End Sub
      Private Sub btnGotoPage_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnGotoPage.Click
        dv.GoToPage(CInt(tbGotoPage.Text))
        ShowCurrentPageNumber()
      End Sub

      Private Sub btnShowcurrentPage_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnShowcurrentPage.Click
        ShowCurrentPageNumber()
      End Sub

      Private Sub dv_PageViewsChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dv.PageViewsChanged
        ShowCurrentPageNumber()
      End Sub
    End Class

    ---------------------------------------

     

     

    Tuesday, May 31, 2011 6:27 PM

Answers

  • i found the right answer

    replace

    dv.GoToPage(CInt(tbGotoPageNumber.Text))
    lblCurrentPage.Content=dv.MasterPageNumber

    with

        AddHandler dv.Document.DocumentPaginator.GetPageCompleted, AddressOf ShowCurrentPage

    Sub ShowCurrentPage()
        lblCurrentPage.Content=dv.MasterPageNumber
    End Sub

    dv.GoToPage(CInt(tbGotoPageNumber.Text))

    -----------------------------

    the handler has to be added before u do any page navigation.

    this will display the correct current page automatically when any page change happens such as: FirstPage, LastPage, NextPage, or PreviousPage

    u don't need to use the PageViewsChanged event, it is useless, i can't figure out for what it is good.

    u don't need to place the     ShowCurrentPageNumber() routine after every page change command. it will be invoked automatically.

    i'm surprized this isn't clearly documented anywhere i looked (since showing the current page is such a common task), i just had to sweat out the  DocumentViewer object model till i figured it out.

     

    Wednesday, June 01, 2011 3:09 PM

All replies

  • i found the right answer

    replace

    dv.GoToPage(CInt(tbGotoPageNumber.Text))
    lblCurrentPage.Content=dv.MasterPageNumber

    with

        AddHandler dv.Document.DocumentPaginator.GetPageCompleted, AddressOf ShowCurrentPage

    Sub ShowCurrentPage()
        lblCurrentPage.Content=dv.MasterPageNumber
    End Sub

    dv.GoToPage(CInt(tbGotoPageNumber.Text))

    -----------------------------

    the handler has to be added before u do any page navigation.

    this will display the correct current page automatically when any page change happens such as: FirstPage, LastPage, NextPage, or PreviousPage

    u don't need to use the PageViewsChanged event, it is useless, i can't figure out for what it is good.

    u don't need to place the     ShowCurrentPageNumber() routine after every page change command. it will be invoked automatically.

    i'm surprized this isn't clearly documented anywhere i looked (since showing the current page is such a common task), i just had to sweat out the  DocumentViewer object model till i figured it out.

     

    Wednesday, June 01, 2011 3:09 PM
  • Hi edMe,

    Thank you for your post and sharing your solution here.

    I suggest that you could post the same issue in only one thread, thank you.

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 02, 2011 4:49 AM
    Moderator