private void PrepareContent() { if (page1 == null) { page1 = new PageForPrinting(); StackPanel header = (StackPanel)page1.FindName("header"); header.Visibility = Windows.UI.Xaml.Visibility.Visible; } PrintContainer.Children.Add(page1); PrintContainer.InvalidateMeasure(); PrintContainer.UpdateLayout(); }
/// <summary> /// Gets the data context of the specified element as a LocationData instance. /// </summary> /// <param name="element">The element bound to the location.</param> /// <returns>The location bound to the element.</returns> private LocationData GetLocation(FrameworkElement element) => (element.FindName("Presenter") as FrameworkElement).DataContext as LocationData;
/// <summary> /// Returns a reference to the sort text block. /// </summary> /// <param name="parent"></param> /// <returns></returns> private TextBlock FindCommentSortText(FrameworkElement parent = null) { // Get if if we don't have it and we can. if (m_commentSortText == null && parent != null) { m_commentSortText = (TextBlock)parent.FindName("ui_commentSortText"); } return m_commentSortText; }
private static object GetTimelineTarget(Control control, FrameworkElement templateRoot, Timeline timeline) { string targetName = Storyboard.GetTargetName(timeline); if (string.IsNullOrEmpty(targetName)) { return null; } if (control is UserControl) { return control.FindName(targetName); } return templateRoot.FindName(targetName); }
/// <summary> /// Method that will generate print content for the scenario /// For scenarios 1-4: it will create the first page from which content will flow /// Scenario 5 uses a different approach /// </summary> /// <param name="page">The page to print</param> public virtual void PreparePrintContent(Page page) { if (firstPage == null) { firstPage = page; StackPanel header = (StackPanel)firstPage.FindName("Header"); header.Visibility = Windows.UI.Xaml.Visibility.Visible; } // Add the (newly created) page to the print canvas which is part of the visual tree and force it to go // through layout so that the linked containers correctly distribute the content inside them. PrintCanvas.Children.Add(firstPage); PrintCanvas.InvalidateMeasure(); PrintCanvas.UpdateLayout(); }
// 提供打印内容 private void PreparedPrintContent() { if (printPage == null) { printPage = new ThreadRelated.Print(); StackPanel header = (StackPanel)printPage.FindName("header"); header.Visibility = Visibility.Visible; } // 向 printingRoot 添加一个打印内容,以便发送到打印机打印 printingRoot.Children.Add(printPage); printingRoot.InvalidateMeasure(); printingRoot.UpdateLayout(); }
// #4 - user has selected a printer so we know paper size, etc. private void OnPaginate(object sender, PaginateEventArgs e) { PrintTaskOptions printingOptions = e.PrintTaskOptions; PrintPageDescription pageDescription = printingOptions.GetPageDescription(0); page1 = new DetailPrinting { DataContext = this.Child, Width = pageDescription.PageSize.Width, Height = pageDescription.PageSize.Height }; // Assumes we have this on our printable page Grid printableArea = (Grid)page1.FindName("printableArea"); // size our grid to the paper dimensions double marginWidth = Math.Max( pageDescription.PageSize.Width - pageDescription.ImageableRect.Width, pageDescription.PageSize.Width * left * 2); double marginHeight = Math.Max( pageDescription.PageSize.Height - pageDescription.ImageableRect.Height, pageDescription.PageSize.Height * top * 2); printableArea.Width = page1.Width - marginWidth; printableArea.Height = page1.Height - marginHeight; // We add the printable page to the visual tree so we can lay it out printContainer.Children.Add(page1); printContainer.InvalidateMeasure(); printContainer.UpdateLayout(); // in our (relatively) simple example we only have one page doc.SetPreviewPageCount(1, PreviewPageCountType.Intermediate); }