Problem using PrintingHeader & Footer

Hello!

I need to create printable grids in out application and found out there is a print Header & Footer (Printing in WPF GridControl control | Syncfusion)

When HeaderHeight and FooterHeight is not set i see my content on page and there is no errors but when i set values to HeaderHeight and FooterHeight after execution of method ShowPrintDialog() i see only white page and in output of visual studio i see exception:

System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=CurrentPageMediaSize; DataItem='GridPrintDialog' (Name='Window'); target element is 'GridSplitButton' (Name='btnPageSizes'); target property is 'SelectedItem' (type 'Object') NullReferenceException:'System.NullReferenceException: Object reference not set to an instance of an object.
   at Syncfusion.Windows.Controls.Grid.GridControlBase.Syncfusion.Windows.Documents.IGridPrintPaginator.GetPrintVisualAt(Int32 pageNumber, Size PageSize)
   at Syncfusion.Windows.Controls.Grid.GridPrintDialog.SetPage(Int32 page)
   at Syncfusion.Windows.Controls.Grid.GridPrintDialog.OnCurrentPageChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at Syncfusion.Windows.Shared.ChromelessWindow.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Syncfusion.Windows.Controls.Grid.GridPrintDialog.SetPageDimensions(PageMediaSizeName pageMediaSizeName)
   at Syncfusion.Windows.Controls.Grid.GridPrintDialog.OnPageMediaSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at Syncfusion.Windows.Shared.ChromelessWindow.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
   at System.Windows.Data.BindingExpression.UpdateSource(Object value)'

           var grid = tableView.GetGrid() as GridControl;
 
           if (tableView.GetTableTitleTextBlock() is TextBlock txtTitleBlock)
           {
               DataTemplate header = new DataTemplate();
               //header.DataType = //typeof()
 
               FrameworkElementFactory txtFactory = new FrameworkElementFactory(typeof(TextBlock));
               txtFactory.SetValue(TextBlock.TextProperty, txtTitleBlock.Text);
 
               txtFactory.SetValue(FrameworkElement.StyleProperty, txtTitleBlock.Style);
               txtFactory.SetValue(TextBlock.TextAlignmentProperty, txtTitleBlock.TextAlignment);
               txtFactory.SetValue(UIElement.VisibilityProperty, txtTitleBlock.Visibility);
 
               header.VisualTree = txtFactory;
               header.Seal();
               grid.PrintHeaderTemplate = header;
               grid.PrintHeaderHeight = 40.0;
               grid.PrintFooterHeight = 40.0;
           }
 
           var result = grid.ShowPrintDialog();

3 Replies 1 reply marked as answer

BT Balamurugan Thirumalaikumar Syncfusion Team February 10, 2021 04:33 PM UTC

Hi Jakub. 
 
Thank you for using syncfusion products. 
 
We have checked your query and given code snippet at our end. The reported issue “When HeaderHeight and FooterHeight is not set i see my content on page and there is no errors but when i set values to HeaderHeight and FooterHeight after execution of method ShowPrintDialog() i see only white page” because of your code snippet have set DataTemplate for PrintHeaderTemplate and set PrintHeaderHeight but DataTemplate for PrintFooterTemplate not set and set PrintFooterHeight. Without DataTemplate we could not set PrintFooterHeight in Gridcontrol. this is cause of the reported issue. We suggest you to  set both DataTemplate and PrintHeaderHeight in gridcontrol. we have prepared a simple sample in following location. Please refer the below sample and code snippet. 
 
CodeSnippet 
  private void Button_Click_1(object sender, RoutedEventArgs e) 
        { 
            DataTemplate header = new DataTemplate(); 
 
            FrameworkElementFactory txtFactory = new FrameworkElementFactory(typeof(TextBlock)); 
            txtFactory.SetValue(TextBlock.TextProperty, "Header"); 
 
            txtFactory.SetValue(FrameworkElement.StyleProperty, txtTitleBlock.Style); 
            txtFactory.SetValue(TextBlock.TextAlignmentProperty, txtTitleBlock.TextAlignment); 
            txtFactory.SetValue(UIElement.VisibilityProperty, txtTitleBlock.Visibility); 
 
            header.VisualTree = txtFactory; 
            header.Seal(); 
            gc.PrintHeaderTemplate = header; 
            gc.PrintHeaderHeight = 40.0; 
            // gc.PrintFooterHeight = 40.0; 
 
            this.gc.ShowPrintDialog(); 
        } 
 
 
Please let us know if you would require further assistance. 
 
Thanks & Regards, 
Balamurugan Thirumalaikumar 


Marked as answer

JM Jakub Marcickiewicz February 10, 2021 04:55 PM UTC

Thank you very much, this is what I needed.

Regards, 
Jakub


BT Balamurugan Thirumalaikumar Syncfusion Team February 11, 2021 06:28 AM UTC

Hi Jakub,

Thank you for the update.

We are glad that the provided sample resolved your requirement. Please get back to us if you have any other requirements.

Regards,
Balamurugan





Loader.
Up arrow icon