private void Button_Click(object sender, RoutedEventArgs e) { VisualBrush visualbrush = new VisualBrush(); visualbrush.Visual = stackpanel; FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); FrameworkElementFactory borderelement = new FrameworkElementFactory(typeof(Border)); borderelement.SetValue(Border.BackgroundProperty, visualbrush); borderelement.SetValue(Border.HeightProperty, 75.0); borderelement.SetValue(Border.WidthProperty, 1020.0); borderelement.SetValue(Border.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); borderelement.SetValue(Border.VerticalAlignmentProperty, VerticalAlignment.Stretch); grid.AppendChild(borderelement); datatemplate.VisualTree = grid; this.datagrid.PrintSettings.AllowRepeatHeaders = false; datagrid.PrintSettings.PrintPageHeaderTemplate = datatemplate; datagrid.PrintSettings.PrintPageHeaderHeight = 55; this.datagrid.ShowPrintPreview(); } |
private void Button_Click(object sender, RoutedEventArgs e) { DataTemplate datatemplate = new DataTemplate(); TextBlock textblock = new TextBlock(); textblock.Text = combobox.SelectedItem.ToString(); FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); FrameworkElementFactory textblockfactory = new FrameworkElementFactory(typeof(TextBlock)); textblockfactory.SetValue(TextBlock.TextProperty, textblock.Text); textblockfactory.SetValue(TextBlock.BackgroundProperty, Brushes.Gray); grid.AppendChild(textblockfactory); datatemplate.VisualTree = grid; this.datagrid.PrintSettings.AllowRepeatHeaders = false; datagrid.PrintSettings.PrintPageHeaderTemplate = datatemplate; datagrid.PrintSettings.PrintPageHeaderHeight = 25; this.datagrid.ShowPrintPreview(); } |