2

I'm using a document to show a user control. Some people from here helped me: How can I put an user control inside a document viewer?

But the user control appers in the corner, and I'd like to print it, but a little bit more central.

Community
  • 1
  • 1
oscar.fimbres
  • 1,145
  • 1
  • 13
  • 24

1 Answers1

4

Repeating my updated answer from the other question..

You can place the UserControl in a Grid which binds its Width/Height to the FixedPage ActualWidth/ActualHeight to achieve centering

<DocumentViewer>
    <FixedDocument>
        <PageContent>
            <FixedPage>
                <Grid Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type FixedPage}},
                                      Path=ActualWidth}"
                      Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type FixedPage}},
                                       Path=ActualHeight}">
                    <local:MyUserControl HorizontalAlignment="Center"
                                         VerticalAlignment="Center"/>
                </Grid>
            </FixedPage>
        </PageContent>
    </FixedDocument>
</DocumentViewer>
Fredrik Hedblad
  • 83,499
  • 23
  • 264
  • 266
  • Only one question Meleak, MyUserControl has a Results property. In window_load, I have a public field where contains a list. I need to pass that list to MyUserControl.Results. I should use binding, or data context? – oscar.fimbres Aug 13 '11 at 02:25
  • @oscar.fimbres: This sounds a bit out of context for the current question so I'm not 100% sure I understand what you want to do. But Bindings only works on properties and not fields to begin with, so if you have a dependency property called Results in your `UserControl` then you could bind this to a Property in your `Window` using DataContext, RelativeSource or ElementName depending on your scenario. You should probably also implement `INotifyPropertyChanaged` in your `Window` so the binding will be updated once the property changes – Fredrik Hedblad Aug 13 '11 at 02:36