Articles in this section
Category / Section

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

2 mins read

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.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied