views:

835

answers:

4

Hi i have a FlowDocument which i want to fill the entire width and height of my window. I have tried using the flowdocumentpageViewer (no luck) and are now using a documentpageview. I still cant get it to dock/fill the entire space, its just sitting in the middle, in the minimum size it can create (does it make sense?)

here is my code:

public DocumentPageView GetPage()
        {
            FlowDocumentPageViewer viewer = new FlowDocumentPageViewer();           
            StreamReader reader = new StreamReader(location);
            string data = reader.ReadToEnd();
            reader.Close();
            string xamlData = HtmlToXamlConverter.ConvertHtmlToXaml(data, true);
            FlowDocument result = (FlowDocument)System.Windows.Markup.XamlReader.Load(new MemoryStream(System.Text.UnicodeEncoding.Default.GetBytes(xamlData)));

            viewer.Document = result;
            viewer.VerticalAlignment = VerticalAlignment.Center;
            viewer.HorizontalAlignment = HorizontalAlignment.Center;

            DocumentPageView pageView = new DocumentPageView();
            pageView.VerticalAlignment = VerticalAlignment.Center;
            pageView.HorizontalAlignment = HorizontalAlignment.Center;
            pageView.Stretch = System.Windows.Media.Stretch.Uniform;
            pageView.PageNumber = 0;
            pageView.StretchDirection = StretchDirection.Both;
            pageView.DocumentPaginator = ((IDocumentPaginatorSource)result).DocumentPaginator;
            return pageView;
        }

Please note that this code contains the combination of my two methods but only the DocumentPageView is currently used. This is the xaml that is created from my HTML source:

<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;
<Paragraph TextAlignment="center" FontSize="22pt" FontFamily="arial">Test Paragraph</Paragraph>
<Paragraph TextAlignment="center" FontFamily="arial">Test second paragraph</Paragraph>
</FlowDocument>

If I resize the fonts the content is only resized vertically (please note that the stretch direction is set to both). Any ideas?

A: 

Hi,

Could you specify where and how do you use the result of your GetPage() method? Is it xbap or desktop application?

I'm asking this, because the following document is displayed just perfectly right in Kaxaml:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  <Grid>  
  <FlowDocumentPageViewer>
  <FlowDocument >
<Paragraph TextAlignment="center" FontSize="22pt" FontFamily="arial">Test Paragraph</Paragraph>
<Paragraph TextAlignment="center" FontFamily="arial">Test second paragraph</Paragraph>
</FlowDocument>
  </FlowDocumentPageViewer>
  </Grid>
</Page>

PS: If it's a desktop application you can always find who causes problems by Snoop tool, form Pete Blois.

Anvaka
The snoop tool says that my: "DocumentPageHost" is only 816px width, this is only half of my resolution. How to change this. I bet this is the one reflecting onto the DocumentPageView which width also only is 816 (811,363636)
H4mm3rHead
Update: I tried to view it in XamlPad, doesnt show up correct. Maybe its is me who is expecting too much. The content is aligned left-top and not center and fill...
H4mm3rHead
:) Now I realize, that my "perfectly right" isn't yours. What exact layout are you trying to get?
Anvaka
A: 

Update: Its a desktop application, the getpage() result is posted into a grid which docks/fills perfectly.

<Window x:Class="GreenWebPlayerWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="Auto" Width="Auto" WindowStyle="None" WindowState="Maximized" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closing="Window_Closing">
    <Grid Width="Auto" Height="Auto" Name="TransitionContainer" Background="White" Margin="0">
        //here the result from GetPage() method is inserted
    </Grid>
</Window>
H4mm3rHead
A: 

(this comment is written from another account)

@Anvaka: What i mean by perfectly right is that the document should "dock in container" that is the fonts should resize, it should fill the container in height and width. Now that im thinking about it, that may not seem like a proper behaviour for a flowdocument.

When i put the flow document in the container it is centered in middle of parent container (so far so good). but the parent container is not filling out its parent container so when i zoom or change font size, i would like the documentPageView container to grow in width and height, but remain centered.

H4mm3rHead
A: 

I had a similar problem with FlowDocumentScrollView, but this solution also seems to work with FlowDocumentPageView:

The FlowDocument is centered because it's PagePadding property is set to auto,auto,auto,auto. Setting PagePadding to 0 fixes this behavior.

<FlowDocumentScrollViewer VerticalScrollBarVisibility="Auto">
    <FlowDocument PagePadding="0">
    </FlowDocument>
</FlowDocumentScrollViewer>
cr7pt0gr4ph7