locked
FlowDocumentPageViewer defaults to last page? RRS feed

  • Question

  • I am currently working on a call center script application in WPF.  Basically, we have a flow document viewer that we are sticking script text into for the call center operators to read.  Based on customer responses they can click buttons to load additional scripts.

    The issue I'm running into is that when I stick a new script into the flowdocument it displays starting on the last page (so if the script is 3 pages, it starts on page 3/3 instead of 1/3).  Not quite sure what I'm missing here, I tried to call the FirstPage() method to no avail:

            <ScrollViewer Height="Auto" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Background="#FFCCCCCC">  
                <DockPanel> 
                    <TextBlock x:Name="txtTitle" DockPanel.Dock="Top" /> 
                    <FlowDocumentPageViewer x:Name="flowScriptPageViewer" DockPanel.Dock="Top" VerticalContentAlignment="Top" Padding="-3,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch">  
                        <FlowDocument x:Name="flowScriptViewer"/>  
                    </FlowDocumentPageViewer> 
                    <ListBox x:Name="lstScriptOptions" Width="Auto" Height="Auto" MinHeight="200">  
                        <ListBox.ItemTemplate> 
                            <DataTemplate> 
                                <Button HorizontalAlignment="Stretch" Tag="{Binding Path=NextScript.ID}" Click="Button_Click">  
                                    <Button.Content> 
                                        <WrapPanel HorizontalAlignment="Stretch">  
                                            <Canvas x:Name="Layer_1" Width="25" Height="25" Canvas.Left="0" Canvas.Top="0">  
                                                <Path x:Name="Path" Width="25" Height="25" Stretch="Fill" Fill="#FFFF5300" Data="F1 M 429.033,297.349C 429.033,286.017 417.232,276.834 402.668,276.834C 388.112,276.834 376.3,286.017 376.3,297.349C 376.3,307.099 385.049,315.242 396.763,317.331C 399.684,324.354 406.726,328.958 414.739,328.49C 415.343,328.464 415.918,328.123 416.185,327.543C 416.567,326.722 416.22,325.76 415.426,325.358C 415.18,325.23 414.896,325.185 414.624,325.194C 414.861,325.185 415.09,325.215 415.33,325.311C 412.045,323.921 409.753,320.988 409.202,317.479C 409.177,317.387 409.177,317.3 409.177,317.209C 420.586,314.953 429.033,306.931 429.033,297.349 Z M 413.939,328.332 Z "/>  
                                            </Canvas> 
                                            <TextBlock Grid.Column="1" Text="{Binding Path=OptionText}" /> 
                                        </WrapPanel> 
                                    </Button.Content> 
                                </Button> 
                            </DataTemplate> 
                        </ListBox.ItemTemplate> 
                    </ListBox> 
                </DockPanel> 
            </ScrollViewer> 

            private void BindScript(Script script)  
            {           
                if (script != null)  
                {  
                    // Set up script in window  
                    flowScriptViewer.Blocks.Clear();  
                    txtTitle.Text = script.Title;  
                    Paragraph MyParagraph = new Paragraph();  
                    MyParagraph.Inlines.Add(script.Text);  
                    MyParagraph.FontSize = 12;                 
                    flowScriptViewer.Blocks.Add(MyParagraph);  
                    flowScriptPageViewer.FirstPage();  
                      
                    lstScriptOptions.ItemsSource = script.ScriptOptions;  
                }             
            }  
     
            private void Button_Click(object sender, RoutedEventArgs e)  
            {  
                Int32 NextScriptID = Convert.ToInt32(((Button) sender).Tag);  
                  
                // see if they want to go back  
                if (NextScriptID == -1)  
                {  
                    // remove the most recent (current) script  
                    _ScriptHistory.RemoveAt(_ScriptHistory.Count - 1);  
                    // bind the one before that  
                    BindScript(_ScriptHistory[_ScriptHistory.Count - 1]);  
                }  
                else 
                {  
                    Script script = ScriptManager.GetScriptByID(NextScriptID);  
                    // Set up Go Back Button  
                    if (_ScriptHistory.Count >= 1)  
                    {  
                        ScriptOptions option = new ScriptOptions();  
                        option.ID = 0;  
                        option.NextScript.ID = -1;  
                        option.OptionText = "Go Back";  
                        script.ScriptOptions.Add(option);  
                    }  
     
                    _ScriptHistory.Add(script);  
                    BindScript(script);  
                } 
    Tuesday, August 12, 2008 3:47 PM

Answers

  • EWISE,

    I run into a similar problem... it seems that when you add blocks and/or inline in a FlowDocument programatically it loses the correct pagination - some time between when it gets the data and when it cauculates the page number and master page - I am not sure. I would love to see more answers from MS over FlowDocument page issues.

    I have a work around that may work for you:

    Add a empty inline in your XAML that will serve as a "anchor" so the DocumentPaginator know where is the first inline and so the first page:

    <FlowDocumentPageViewer x:Name="flowScriptPageViewer" DockPanel.Dock="Top" VerticalContentAlignment="Top" Padding="-3,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch">   
     
    <FlowDocument x:Name="flowScriptViewer">   
       <Paragraph> 
          <Run x:name="ThisIsYourAnchorInline" /> 
          <Run x:Name="ScriptText" /> 
       </Paragraph> 
    </FlowDocument> 
     
    </FlowDocumentPageViewer>  

    In your code behind set the ScriptText.Text to your text.







    • Marked as answer by EWISE Friday, August 15, 2008 2:46 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:46 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:47 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:47 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:47 AM
    Thursday, August 14, 2008 5:26 PM

All replies

  • EWISE,

    I run into a similar problem... it seems that when you add blocks and/or inline in a FlowDocument programatically it loses the correct pagination - some time between when it gets the data and when it cauculates the page number and master page - I am not sure. I would love to see more answers from MS over FlowDocument page issues.

    I have a work around that may work for you:

    Add a empty inline in your XAML that will serve as a "anchor" so the DocumentPaginator know where is the first inline and so the first page:

    <FlowDocumentPageViewer x:Name="flowScriptPageViewer" DockPanel.Dock="Top" VerticalContentAlignment="Top" Padding="-3,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch">   
     
    <FlowDocument x:Name="flowScriptViewer">   
       <Paragraph> 
          <Run x:name="ThisIsYourAnchorInline" /> 
          <Run x:Name="ScriptText" /> 
       </Paragraph> 
    </FlowDocument> 
     
    </FlowDocumentPageViewer>  

    In your code behind set the ScriptText.Text to your text.







    • Marked as answer by EWISE Friday, August 15, 2008 2:46 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:46 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:47 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:47 AM
    • Marked as answer by EWISE Friday, August 15, 2008 2:47 AM
    Thursday, August 14, 2008 5:26 PM
  • That did the trick, it's a pretty wonky hack though.  I too would like to see someone from MS look into this.
    Friday, August 15, 2008 2:46 AM