How to remove the grey background from pdf viewer

6 posts, 0 answers
  1. Mohammad
    Mohammad avatar
    2 posts
    Member since:
    May 2012

    Posted 22 May 2012 Link to this post

    Hi,
    q1 : I want to remove the grey background from the pdfviewer (for making a style)?

    Is there a way to do this?

    thanks
  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 23 May 2012 Link to this post

    Hi Mohammad,

    All you need to do to change the background of a RadPDF viewer is create a new static resource template for the PDFviewer control. In the template, locate the root grid and add a background property. Select what color you want it to be here.

    I've written you an example that you can copy and paste into a new project. I've changed the background to black.
    <Window x:Class="PDFviewerExample.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <telerik:Office_BlackTheme x:Key="Theme"/>
            <ControlTemplate x:Key="FixedDocumentViewerBaseTemplate" TargetType="telerik:RadPdfViewer">
         <!-- HERE is where you can alter the root background color -->
                <Grid Background="Black">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <ContentControl x:Name="PART_ContentPresenter" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"/>
                        <ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="1" Orientation="Vertical" telerik:StyleManager.Theme="{StaticResource Theme}" Visibility="Collapsed"/>
                        <ScrollBar x:Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" telerik:StyleManager.Theme="{StaticResource Theme}" Visibility="Collapsed"/>
                    </Grid>
                    <telerik:RadBusyIndicator x:Name="PART_BusyIndicator" Grid.RowSpan="2" telerik:StyleManager.Theme="{StaticResource Theme}"/>
                </Grid>
            </ControlTemplate>
            <Style x:Key="RadPdfViewerStyle1" TargetType="telerik:RadPdfViewer">
                <Setter Property="Template" Value="{StaticResource FixedDocumentViewerBaseTemplate}"/>
            </Style>
        </Window.Resources>
         
            <Grid>
            <telerik:RadPdfViewer Style="{StaticResource RadPdfViewerStyle1}">
     
            </telerik:RadPdfViewer>
        </Grid>
    </Window>



    If you have any other questions feel free to reply, I will be subscribed to this thread.

    Good luck!
    Lancelot
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mohammad
    Mohammad avatar
    2 posts
    Member since:
    May 2012

    Posted 24 May 2012 Link to this post

    Hi Lancelot,

    Thank you for your answer.
    The problem hasn't been solved yet. When a pdf file is loaded, the grey background appears.
    The grey color is because of the content control of the pdf viewer. Is there any way to change its background?

    Thanks!
  5. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 24 May 2012 Link to this post

    Hi Mohammad,

    I see what you are trying to do. You have two main options. The first and honestly the best way would be to use the built in themes the RadControls come with. Here is a link to see them in action on the RadPDFviewer (keep in mind you'll be looking at the Silverlight demo, but it is the same for WPF). Click on this link (http://demos.telerik.com/silverlight/#PdfViewer/Theming) to go to the PDFviewer Theming example.
     
    On the left hand side you'll see the option to change the theme. Go ahead and try out all the different themes. If you like one of them, then all you need to do is set the theme. This link (http://www.telerik.com/help/wpf/common-styling-apperance-setting-theme-wpf.html) will bring you to the WPF documentation on how to set the theme, its just a couple lines of code.

    You second option is to edit the content template. This link (http://www.telerik.com/help/wpf/common-styling-appearance-edit-control-templates-blend.html) will give you the basics on how to edit a control's style. Telerik does offer custom theme styling if your organization wants to create a completely custom control. Contact telerik Professional Services for more on that.
    Good luck,
    Lancelot
  6. AvgurD
    AvgurD avatar
    18 posts
    Member since:
    Oct 2012

    Posted 17 Jul 2012 Link to this post

    Hi!
    I want to change default template for PdfViewer in Metro theme - change white backround for gray or black. How I can do it? Without switch to other theme for this control (its not good - dll with theme have big size - just for one control its too expensive)?
    I trying find this color in template of PdfViewer (in Blend) but all my changes of brushe had no effect. :(

    Sorry for terrible English! 
  7. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 18 Jul 2012 Link to this post

    Hello Dmitry,

    All you need to do is to create your own style for the FixedDocumentPagesPresenter. Here is sample code that sets the Background blue.

    <Style TargetType="ui:FixedDocumentPagesPresenter">
               <Setter Property="Background" Value="Blue" />
               <Setter Property="BorderThickness" Value="0" />
               <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>

    Kind regards,
    Kammen
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready