/// <summary> /// When a request for image source completes, remove the requesting ImageControl from the list of pending request states. /// If all pending requests have been completed, raise conversion completed event /// </summary> protected virtual void OnGetImageSourceCompleted(object sender, GetImageSourceCompletedEventArgs e) { if (sender is PrintableStoryImageControl) { PrintableStoryImageControl imageControl = (PrintableStoryImageControl)sender; if (_pendingImageRequestStates.Contains(imageControl)) { _pendingImageRequestStates.Remove(imageControl); } imageControl.GetImageSourceCompleted -= GetImageSourceCompleted; } if (_pendingImageRequestStates.Count == 0) { // _userState is the target document ConversionCompletedEventArgs args = new ConversionCompletedEventArgs(_requestedUserState, _targetDocument); _dispatcher.BeginInvoke(DispatcherPriority.Input, new DispatcherOperationCallback(RaiseConversionCompleted), args); _requestedUserState = null; } }
/// <summary> /// Creates a paragraph with a PrintableStoryImageControl to display images, and adds the control to the list of pending image requests /// </summary> protected virtual Paragraph CreateImageParagraph(Story story, ImageReference imageReference, ImageData imageData, FlowDocumentStyleProvider styleProvider) { PrintableStoryImageControl imageControl = new PrintableStoryImageControl(); imageControl.ImageReference = imageReference; imageControl.ImageData = imageData; imageControl.Story = story; MsdnStoryToFlowDocumentConverter.ApplyStyle(imageControl, GetImageControlStyle(styleProvider)); // Add the image control to the list of pending image request states if (_pendingImageRequestStates == null) { _pendingImageRequestStates = new List <PrintableStoryImageControl>(); } _pendingImageRequestStates.Add(imageControl); HeightAligner heightAligner = CreateHeightAligner(imageControl, WhitespaceDistribution.Split, styleProvider); Figure imageFigure = new Figure(new BlockUIContainer(heightAligner)); // Image figure may not be styled since we need to set its content and anchoring if (imageData.Width < 600) { imageFigure.Width = new FigureLength(1, FigureUnitType.Column); imageFigure.VerticalAnchor = FigureVerticalAnchor.ContentBottom; imageFigure.HorizontalAnchor = FigureHorizontalAnchor.ColumnCenter; } else { imageFigure.Width = new FigureLength(2, FigureUnitType.Column); imageFigure.VerticalAnchor = FigureVerticalAnchor.ContentBottom; imageFigure.HorizontalAnchor = FigureHorizontalAnchor.ContentLeft; } Paragraph imageParagraph = new Paragraph(imageFigure); MsdnStoryToFlowDocumentConverter.ApplyStyle(imageParagraph, GetImageContainerStyle(styleProvider)); return(imageParagraph); }