We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize the header or footer of the print preview in the WPF Diagram (SfDiagram)?

Platform: WPF |
Control: SfDiagram |
Published Date: April 30, 2020 |
Last Revised Date: July 15, 2021

Header and Footer for the print preview window can be enabled by using the PageHeaderHeight and PageFooterHeight properties in the PrintSettings property of PrintingService class of WPF Diagram (SfDiagram). The Appearance of the footer and header text can be modified by using the PageHeaderTemplate and PageFooterTemplate properties.

XAML

<Application.Resources>
  <DataTemplate x:Key="PrintHeaderTemplate">
    <TextBlock Text="PageHeader" FontSize="35" FontStyle="Italic" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
  </DataTemplate>
  <DataTemplate x:Key="PrintFooterTemplate">
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" FontSize="12">
      <TextBlock.Text>
        <Binding Path="PageIndex" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type Printing:PrintPageControl}}" StringFormat="Page : {0}" />
      </TextBlock.Text>
    </TextBlock>
  </DataTemplate>
</Application.Resources>

C#

public partial class MainWindow : Window
{
  public MainWindow()
  {
    InitializeComponent();
    SfDiagram Diagram = new SfDiagram();
    Diagram.PrintingService.PrintSettings.PageHeaderHeight = 100;
    Diagram.PrintingService.PrintSettings.PageHeaderTemplate = App.Current.Resources["PrintHeaderTemplate"] as DataTemplate;
    Diagram.PrintingService.PrintSettings.PageFooterHeight = 100;
    Diagram.PrintingService.PrintSettings.PageFooterTemplate = App.Current.Resources["PrintFooterTemplate"] as DataTemplate;
  }
}    

 

View sample in GitHub.

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile