This is a migrated thread and some comments may be shown as answers.

How to change background of PDF page itself?

3 Answers 144 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 18 Apr 2013, 09:38 PM
I'm working on a project using RadPDFViewer. We've implemented multiple Windows 8 style themes with the following code snippet:

Windows8Palette.Palette.MainColor = ((SolidColorBrush)dictionary["BasicControlBackground"]).Color;
Windows8Palette.Palette.AccentColor = ((SolidColorBrush)dictionary["BasicDarkAccentColor"]).Color;
Windows8Palette.Palette.BasicColor = ((SolidColorBrush)dictionary["BasicHighlightColor"]).Color;
Windows8Palette.Palette.StrongColor = ((SolidColorBrush)dictionary["BasicControlForegroundColor"]).Color;
Windows8Palette.Palette.MarkerColor = ((SolidColorBrush)dictionary["BasicDarkAccentColor"]).Color;
 
StyleManager.ApplicationTheme = new Windows8Theme();

...in which the color brushes above are swapped out at runtime inside merged resource dictionaries.This gives us the ability to create a Light/Dark theme controlled by a dropdown.

However, we're finding that the colors used in some of the controls aren't acting the way we want (focus color in one control seems be be used for content elswhere), so we're customizing the templates. We've had good success with this approach so far, but the PDFViewer is being difficult.

Specifically, we want to force the page of the pdf (ie: just the area under the pdf itself, not the border around the page) to be white regardless of what background color we're using in other controls.

There seem to be a few possibilities for achieving this:
- Using a different theme (Office Dark, Vista etc...) for the PDFViewer and applying it explicitly. The downside is that we will no longer be able to apply an application wide theme and will have to specify the Windows 8 theme on all other controls.
- Figuring out how to override the template of the PDFViewer in a way that provides access to the page background. I haven't been able to figure this out.
- Applying different values for the Windows 8 palette for just the PDFViewer. As near as I can tell, the palette is global so no way to do it.

Is there a smarter way to go about this?

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 19 Apr 2013, 12:49 PM
Hi Andrew,

Thank you for contacting us.

As I understand, your concern is about the background of the PagesPresenter which is "under" the Page.

To change that, you should apply a style to it explicitly. It should look like that:

<Style TargetType="ui:FixedDocumentPagesPresenter">
            <Setter Property="Background" Value="Yellow" />
            <Setter Property="BorderBrush" Value="Red" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ui:FixedDocumentPagesPresenter">
                        <Grid>
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                <ContentPresenter Margin="{TemplateBinding Padding}" />
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Where "ui" is a prefix for the following namespace:
xmlns:ui="clr-namespace:Telerik.Windows.Documents.UI;assembly=Telerik.Windows.Controls.FixedDocumentViewers"        

Hope this helps. Let us know how it goes.
 
All the best,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Andrew
Top achievements
Rank 1
answered on 19 Apr 2013, 04:29 PM
Hi Todor,

Unfortunately that code isn't affecting the region I'm after. I've attached a screenshot of the output I get with that style.

The part I'm trying to change is the page background itself, which is controlled by Windows8Palette.Palette.MainColor.

Is there a style for affecting that part of the control?
0
Todor
Telerik team
answered on 22 Apr 2013, 11:23 AM
Hello Andrew,

Sorry for the misunderstanding. 

If you want to affect the actual Page appearance, you should point as a target of your style fixedui:Page element, instead of ui:FixedDocumentPagesPresenter, where "fixedui" is a prefix for the following namespace:
xmlns:fixedui="clr-namespace:Telerik.Windows.Documents.Fixed.UI;assembly=Telerik.Windows.Controls.FixedDocumentViewers"

You can add that style and it will affect exactly what you want:
<Style TargetType="fixedui:Page">
           <Setter Property="Background" Value="Red" />
           <Setter Property="BorderBrush" Value="Green" />
           <Setter Property="BorderThickness" Value="1" />
           <Setter Property="Padding" Value="0" />
           <Setter Property="Template">
               <Setter.Value>
                   <ControlTemplate TargetType="fixedui:Page">
                       <Border x:Name="PART_LayoutRoot">
                           <Grid>
                               <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
                                   BorderThickness="{TemplateBinding BorderThickness}" Margin="-10" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                               </Border>
                           </Grid>
                       </Border>
                   </ControlTemplate>
               </Setter.Value>
           </Setter>
       </Style>

I hope that this will help.


All the best,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PDFViewer
Asked by
Andrew
Top achievements
Rank 1
Answers by
Todor
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or