public void ArrangeTest () { Border b1 = new Border (); b1.Background = new SolidColorBrush (Colors.Red); b1.Width = 50; b1.Height = 25; Border b2 = new Border (); b2.Background = new SolidColorBrush (Colors.Blue); b2.Width = 25; b2.Height = 30; var stack = new StackPanel (); stack.Children.Add (b1); stack.Children.Add (b2); stack.Measure (new Size (Double.PositiveInfinity,Double.PositiveInfinity)); Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired"); Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual"); stack.Arrange (new Rect (10, 10, stack.DesiredSize.Width, stack.DesiredSize.Height)); Assert.AreEqual (new Size (50,55), stack.DesiredSize, "stack desired1"); Assert.AreEqual (new Size (50,55), stack.RenderSize, "stack render1"); Assert.AreEqual (new Rect (10,10,50,55), LayoutInformation.GetLayoutSlot (stack), "stack slot"); }
public void StackPanelLayoutTest() { StackPanel panel = new StackPanel(); FrameworkElement child1 = new FrameworkElement { Height = 100 }; FrameworkElement child2 = new FrameworkElement { Height = 100 }; FrameworkElement child3 = new FrameworkElement { Height = 100 }; panel.Children.Add(child1); panel.Children.Add(child2); panel.Children.Add(child3); panel.Measure(new Size(1000, 1000)); Assert.AreEqual(new Size(0, 300), panel.DesiredSize); panel.Arrange(new Rect(1000, 300)); Assert.AreEqual(new Size(1000, 300), panel.VisualSize); Assert.AreEqual(new Size(1000, 100), child1.VisualSize); Assert.AreEqual(new Size(1000, 100), child2.VisualSize); Assert.AreEqual(new Size(1000, 100), child3.VisualSize); Assert.AreEqual(new Point(0, 0), child1.VisualOffset); Assert.AreEqual(new Point(0, 100), child2.VisualOffset); Assert.AreEqual(new Point(0, 200), child3.VisualOffset); }
void BuildDrawing() { this.drawing = new GeometryDrawing(); // Use geometries to describe two overlapping ellipses. EllipseGeometry ellipse1 = new EllipseGeometry(); ellipse1.RadiusX = 20; ellipse1.RadiusY = 45; ellipse1.Center = new Point(50, 50); EllipseGeometry ellipse2 = new EllipseGeometry(); ellipse2.RadiusX = 45; ellipse2.RadiusY = 20; ellipse2.Center = new Point(50, 50); GeometryGroup ellipses = new GeometryGroup(); ellipses.Children.Add(ellipse1); ellipses.Children.Add(ellipse2); // Add the geometry to the drawing. this.drawing.Geometry = ellipses; // Specify the drawing's fill. this.drawing.Brush = Brushes.Blue; // Specify the drawing's stroke. Pen stroke = new Pen(); stroke.Thickness = 10.0; stroke.Brush = new LinearGradientBrush( Colors.Black, Colors.Gray, new Point(0, 0), new Point(1, 1)); this.drawing.Pen = stroke; // Create a DrawingBrush DrawingBrush myDrawingBrush = new DrawingBrush(); myDrawingBrush.Drawing = this.drawing; // Create a Rectangle element. Rectangle aRectangle = new Rectangle(); aRectangle.Width = 150; aRectangle.Height = 150; aRectangle.Stroke = Brushes.Black; aRectangle.StrokeThickness = 1.0; // Use the DrawingBrush to paint the rectangle's // background. aRectangle.Fill = myDrawingBrush; StackPanel mainPanel = new StackPanel(); mainPanel.Children.Add(aRectangle); mainPanel.Arrange(new Rect(100, 100, 500, 500)); //this.drawing2 = mainPanel; //this.Content = mainPanel; }
public void LayoutSlotTest () { var stack = new StackPanel (); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); stack.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); stack.Arrange (new Rect (0,0,stack.DesiredSize.Width,stack.DesiredSize.Height)); Assert.AreEqual (new Rect (0,0,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0])); Assert.AreEqual (new Rect (0,33,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1])); Assert.AreEqual (new Rect (0,66,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2])); }
public void MouseDeviceCaptureTest() { Border child1 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 }; Border child2 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 }; Border child3 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 }; StackPanel panel = new StackPanel { IsRootElement = true }; panel.Children.Add(child1); panel.Children.Add(child2); MouseEventArgs lastArgs = null; panel.MouseMove += (sender, e) => lastArgs = e; TestPresentationSource presentationSource = new TestPresentationSource(); presentationSource.RootElement = panel; panel.Measure(Size.Infinity); panel.Arrange(new Rect(panel.DesiredSize)); MouseDevice mouseDevice = new MouseDevice(presentationSource); mouseDevice.Activate(); mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0)); Assert.AreEqual(child1, lastArgs.Source); Assert.AreEqual(child1, mouseDevice.HitTarget); Assert.AreEqual(null, mouseDevice.CaptureTarget); Assert.AreEqual(child1, mouseDevice.Target); mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 150), 0)); Assert.AreEqual(child2, lastArgs.Source); Assert.AreEqual(child2, mouseDevice.HitTarget); Assert.AreEqual(null, mouseDevice.CaptureTarget); Assert.AreEqual(child2, mouseDevice.Target); mouseDevice.Capture(child2); mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0)); Assert.AreEqual(child2, lastArgs.Source); Assert.AreEqual(child1, mouseDevice.HitTarget); Assert.AreEqual(child2, mouseDevice.CaptureTarget); Assert.AreEqual(child2, mouseDevice.Target); mouseDevice.ReleaseCapture(); mouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0)); Assert.AreEqual(child1, lastArgs.Source); Assert.AreEqual(child1, mouseDevice.HitTarget); Assert.AreEqual(null, mouseDevice.CaptureTarget); Assert.AreEqual(child1, mouseDevice.Target); }
internal void Print(System.Windows.Controls.Image ImageCtrl) { PrintDialog printDlg = new PrintDialog(); if (printDlg.ShowDialog() == true) { printDlg.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.NorthAmerica4x6); printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape; System.Windows.Size size = new System.Windows.Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight); StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size }; //TextBlock title = new TextBlock { Text = @"Form", FontSize = 20 }; //stackPanel.Children.Add(title); TransformGroup transformGroup = new TransformGroup(); ScaleTransform scaleTransform = new ScaleTransform(1,1); transformGroup.Children.Add(scaleTransform); Image image = new Image { Source = ImageCtrl.Source, Stretch = Stretch.Uniform }; //image.RenderTransform = new ScaleTransform(1, 1); BitmapSource imgSrouce = ImageCtrl.Source as BitmapSource; if (imgSrouce.PixelWidth < imgSrouce.PixelHeight) { image.LayoutTransform = new RotateTransform(90); } image.RenderTransform = transformGroup; stackPanel.Children.Add(image); stackPanel.Measure(size); stackPanel.Arrange(new Rect(new Point(0, 0), stackPanel.DesiredSize)); printDlg.PrintVisual(stackPanel, @"Form image"); //printDlg.PrintVisual(ImageCtrl, "My First Print Job"); } }
private void Print_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); if (printDlg.ShowDialog() == true) { printDlg.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.NorthAmerica4x6); //printDlg.PrintQueue.DefaultPrintTicket.PageOrientation = PageOrientation.Landscape; printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape; Console.WriteLine("wwwwwwwwwwwwww->" + printDlg.PrintableAreaWidth); Console.WriteLine("hhhhhhhhhhhhhhh->" + printDlg.PrintableAreaHeight); Console.WriteLine("W-> "+printDlg.PrintTicket.PageMediaSize.Width); Console.WriteLine("H-> "+printDlg.PrintTicket.PageMediaSize.Height); //printDlg.PrintQueue.DefaultPrintTicket.PageOrientation = PageOrientation.Portrait; /* XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(printDlg.PrintQueue); PrintTicket ticket = new PrintTicket(); if (printDlg.PrintTicket.PageOrientation == PageOrientation.Landscape) { ticket.PageMediaSize = new PageMediaSize(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight); } docWriter.Write(visual, ticket); */ Size size = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight); StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size }; //TextBlock title = new TextBlock { Text = @"Form", FontSize = 20 }; //stackPanel.Children.Add(title); Image image = new Image { Source = this.theImage.Source, Stretch = Stretch.Uniform }; image.RenderTransform = new ScaleTransform(1, 1); stackPanel.Children.Add(image); stackPanel.Measure(size); stackPanel.Arrange(new Rect(new Point(0, 0), stackPanel.DesiredSize)); printDlg.PrintVisual(stackPanel, @"Form image"); //printDlg.PrintVisual(theImage, "My First Print Job"); } }
public void HitTestBasicTest() { StackPanel stackPanel1 = new StackPanel { Name = "stackPanel1", Background = Brushes.Transparent, IsRootElement = true }; StackPanel stackPanel2 = new StackPanel { Name = "stackPanel2", Background = Brushes.Transparent, Height = 100, Orientation = Orientation.Horizontal }; Border child1 = new Border { Name = "child1", Background = Brushes.Transparent, Height = 100, Width = 100 }; Border child2 = new Border { Name = "child2", Background = Brushes.Transparent, Height = 100 }; Border child3 = new Border { Name = "child3", Background = Brushes.Transparent, Width = 100 }; Border child4 = new Border { Name = "child4", Background = Brushes.Transparent, Width = 100 }; stackPanel1.Children.Add(child1); stackPanel1.Children.Add(stackPanel2); stackPanel1.Children.Add(child2); stackPanel2.Children.Add(child3); stackPanel2.Children.Add(child4); // [child1] ] // [child3][child4] // [child2 ] stackPanel1.Measure(Size.Infinity); stackPanel1.Arrange(new Rect(stackPanel1.DesiredSize)); Assert.AreEqual(child1, stackPanel1.HitTest(new Point(50, 50))); Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 50))); Assert.AreEqual(child3, stackPanel1.HitTest(new Point(50, 150))); Assert.AreEqual(child4, stackPanel1.HitTest(new Point(150, 150))); Assert.AreEqual(child2, stackPanel1.HitTest(new Point(50, 250))); Assert.AreEqual(child2, stackPanel1.HitTest(new Point(150, 250))); stackPanel2.IsEnabled = false; Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 150))); Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 150))); child2.IsHitTestVisible = false; Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 250))); Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 250))); }
private void Window_Loaded(object sender, RoutedEventArgs e) { System.Windows.Size size = new System.Windows.Size(600, 400); StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size }; System.Windows.Controls.Image ImageCtrl = new System.Windows.Controls.Image(); BitmapImage bitImg = new BitmapImage(new Uri("C:\\temp\\32367-78aNJdO.jpg")); ImageCtrl.Source = bitImg; TransformGroup transformGroup = new TransformGroup(); ScaleTransform scaleTransform = new ScaleTransform(1, 1); transformGroup.Children.Add(scaleTransform); System.Windows.Controls.Image image = new System.Windows.Controls.Image { Source = ImageCtrl.Source, Stretch = Stretch.Uniform }; //image.RenderTransform = new ScaleTransform(1, 1); BitmapSource imgSrouce = ImageCtrl.Source as BitmapSource; if (imgSrouce.PixelWidth < imgSrouce.PixelHeight) { /* double argle = 90 * 180 / 3.142; RotateTransform rotateTransform = new RotateTransform(); rotateTransform.Angle = argle; transformGroup.Children.Add(rotateTransform); * */ image.LayoutTransform = new RotateTransform(90); } image.RenderTransform = transformGroup; stackPanel.Children.Add(image); stackPanel.Measure(size); stackPanel.Arrange(new Rect(new System.Windows.Point(0, 0), stackPanel.DesiredSize)); this.AddChild(stackPanel); }
public void LayoutSlotTest_Flow () { var stack = new StackPanel (); var border = new Border () { Width = 100, Height = 200 }; border.Child = stack; stack.FlowDirection = FlowDirection.RightToLeft; stack.Orientation = Orientation.Horizontal; var child0 = CreateSlotItem (); var child1 = CreateSlotItem (); child1.FlowDirection = FlowDirection.LeftToRight; stack.Children.Add (child0); stack.Children.Add (child1); stack.Children.Add (CreateSlotItem ()); stack.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); stack.Arrange (new Rect (0,0,stack.DesiredSize.Width,stack.DesiredSize.Height)); Assert.AreEqual (new Rect (0,0,25,33), LayoutInformation.GetLayoutSlot (child0)); Assert.AreEqual (new Rect (25,0,25,33), LayoutInformation.GetLayoutSlot (child1)); Assert.AreEqual (new Rect (50,0,25,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2])); CreateAsyncTest (border, () => { MatrixTransform xform0 = child0.TransformToVisual (border) as MatrixTransform; Assert.AreEqual ("-1,0,0,1,100,84", xform0.Matrix.ToString(), "transform0 string"); MatrixTransform xform1 = child1.TransformToVisual (border) as MatrixTransform; Assert.AreEqual ("1,0,0,1,50,84", xform1.Matrix.ToString(), "transform1 string"); MatrixTransform xform0_st = child0.TransformToVisual (stack) as MatrixTransform; Assert.AreEqual ("1,0,0,1,0,84", xform0_st.Matrix.ToString(), "transform0_st string"); MatrixTransform xform1_st = child1.TransformToVisual (stack) as MatrixTransform; Assert.AreEqual ("-1,0,0,1,50,84", xform1_st.Matrix.ToString(), "transform1_st string"); }); }
private void Print_Click(object sender, RoutedEventArgs e) { PrintDialog dialog = new PrintDialog(); if (dialog.ShowDialog() == true) { StackPanel panel = new StackPanel(); panel.Margin = new Thickness(15); panel.Children.Add((Canvas)XamlReader.Parse(XamlWriter.Save(this.DrawingHost.DrawingControl))); TextBlock myBlock = new TextBlock(); myBlock.Text = "Drawing"; myBlock.TextAlignment = TextAlignment.Center; panel.Children.Add(myBlock); panel.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight)); panel.Arrange(new Rect(new System.Windows.Point(0, 0), panel.DesiredSize)); dialog.PrintTicket.PageOrientation = PageOrientation.Landscape; dialog.PrintVisual(panel, "Drawing"); } }
Composite ( Double compositeWidth, Double compositeHeight, String headerText, String footerText, System.Drawing.Font headerFooterFont, IEnumerable<LegendControlBase> legendControls ) { Debug.Assert(compositeWidth > 0); Debug.Assert(compositeHeight > 0); Debug.Assert(headerFooterFont != null); Debug.Assert(legendControls != null); AssertValid(); // Note: // // Don't try taking a shortcut by using // NodeXLControl.CopyGraphToBitmap() to get an image of the graph and // then compositing the image with the other elements. That would work // if the caller were creating an image, but if it were creating an XPS // document, the graph would no longer be scalable. Double dScreenDpi = WpfGraphicsUtil.GetScreenDpi(m_oNodeXLControl).Width; // The NodeXLControl can't be a child of two logical trees, so // disconnect it from its parent after saving the current vertex // locations. m_oLayoutSaver = new LayoutSaver(m_oNodeXLControl.Graph); Debug.Assert(m_oNodeXLControl.Parent is Panel); m_oParentPanel = (Panel)m_oNodeXLControl.Parent; UIElementCollection oParentChildren = m_oParentPanel.Children; m_iChildIndex = oParentChildren.IndexOf(m_oNodeXLControl); oParentChildren.Remove(m_oNodeXLControl); m_oGraphImageScaler = new GraphImageScaler(m_oNodeXLControl); m_oGraphImageCenterer = new NodeXLControl.GraphImageCenterer( m_oNodeXLControl); // The header and footer are rendered as Label controls. The legend is // rendered as a set of Image controls. Label oHeaderLabel, oFooterLabel; IEnumerable<Image> oLegendImages; Double dHeaderHeight, dTotalLegendHeight, dFooterHeight; CreateHeaderOrFooterLabel(headerText, compositeWidth, headerFooterFont, out oHeaderLabel, out dHeaderHeight); CreateLegendImages(legendControls, compositeWidth, out oLegendImages, out dTotalLegendHeight); CreateHeaderOrFooterLabel(footerText, compositeWidth, headerFooterFont, out oFooterLabel, out dFooterHeight); m_oNodeXLControl.Width = compositeWidth; m_oNodeXLControl.Height = Math.Max(10, compositeHeight - dHeaderHeight - dTotalLegendHeight - dFooterHeight); // Adjust the control's graph scale so that the graph's vertices and // edges will be the same relative size in the composite that they are // in the control. m_oGraphImageScaler.SetGraphScale( (Int32)WpfGraphicsUtil.WpfToPx(compositeWidth, dScreenDpi), (Int32)WpfGraphicsUtil.WpfToPx(m_oNodeXLControl.Height, dScreenDpi), dScreenDpi); // Adjust the NodeXLControl's translate transforms so that the // composite will be centered on the same point on the graph that the // NodeXLControl is centered on. m_oGraphImageCenterer.CenterGraphImage( new Size(compositeWidth, m_oNodeXLControl.Height) ); StackPanel oStackPanel = new StackPanel(); UIElementCollection oStackPanelChildren = oStackPanel.Children; // To avoid a solid black line at the bottom of the header or the top // of the footer, which is caused by rounding errors, make the // StackPanel background color the same as the header and footer. oStackPanel.Background = HeaderFooterBackgroundBrush; if (oHeaderLabel != null) { oStackPanelChildren.Add(oHeaderLabel); } // Wrap the NodeXLControl in a Grid to clip it. m_oGrid = new Grid(); m_oGrid.Width = m_oNodeXLControl.Width; m_oGrid.Height = m_oNodeXLControl.Height; m_oGrid.ClipToBounds = true; m_oGrid.Children.Add(m_oNodeXLControl); oStackPanelChildren.Add(m_oGrid); foreach (Image oLegendImage in oLegendImages) { oStackPanelChildren.Add(oLegendImage); } if (oFooterLabel != null) { oStackPanelChildren.Add(oFooterLabel); } Size oCompositeSize = new Size(compositeWidth, compositeHeight); Rect oCompositeRectangle = new Rect(new Point(), oCompositeSize); oStackPanel.Measure(oCompositeSize); oStackPanel.Arrange(oCompositeRectangle); oStackPanel.UpdateLayout(); return (oStackPanel); }
public void StackPanelMarginTest() { StackPanel panel = new StackPanel { Orientation = Orientation.Horizontal }; FrameworkElement child1 = new FrameworkElement { Width = 80, Margin = new Thickness(10) }; FrameworkElement child2 = new FrameworkElement { Width = 60, Margin = new Thickness(20) }; FrameworkElement child3 = new FrameworkElement { Width = 40, Margin = new Thickness(30) }; panel.Children.Add(child1); panel.Children.Add(child2); panel.Children.Add(child3); panel.Measure(new Size(1000, 1000)); Assert.AreEqual(new Size(300, 60), panel.DesiredSize); panel.Arrange(new Rect(300, 1000)); Assert.AreEqual(new Size(300, 1000), panel.VisualSize); Assert.AreEqual(new Size(80, 980), child1.VisualSize); Assert.AreEqual(new Size(60, 960), child2.VisualSize); Assert.AreEqual(new Size(40, 940), child3.VisualSize); Assert.AreEqual(new Point(10, 10), child1.VisualOffset); Assert.AreEqual(new Point(120, 20), child2.VisualOffset); Assert.AreEqual(new Point(230, 30), child3.VisualOffset); }
public void MinWidthOnParentTest () { StackPanel sp = new StackPanel { MinWidth = 200 }; LayoutPoker c = new LayoutPoker { Height = 25 }; sp.Children.Add (c); sp.Measure (new Size (100, 100)); Assert.AreEqual (new Size (200,25), c.MeasureArg, "c.Measure"); Assert.AreEqual (new Size (0,25), c.DesiredSize); sp.Arrange (new Rect (0, 0, 100, 100)); Assert.AreEqual (new Size (200,25), c.ArrangeArg, "c.Arrange"); // now check desired/render sizes // the child is oblivious to the parent's maxheight Assert.AreEqual (new Size (0,0), c.RenderSize, "c.RenderedSize"); Assert.AreEqual (new Size (0,25), c.DesiredSize, "c.DesiredSize"); Assert.IsNull (LayoutInformation.GetLayoutClip (c), "c.LayoutClip == null"); // the parent's maxheight clips Assert.AreEqual (new Size (200,100), sp.RenderSize, "sp.RenderSize"); Assert.AreEqual (new Size (100,25), sp.DesiredSize, "sp.DesiredSize"); Assert.IsNotNull (LayoutInformation.GetLayoutClip (sp), "sp.LayoutClip != null"); }
public void MouseDeviceQueryCursorTest() { Border child1 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 }; Border child2 = new Border { Background = Brushes.Transparent, Width = 100, Height = 100 }; StackPanel panel = new StackPanel { IsRootElement = true }; panel.Children.Add(child1); panel.Children.Add(child2); TestPresentationSource presentationSource = new TestPresentationSource(); presentationSource.RootElement = panel; ((TestApplicationHost)ApplicationHost.Current).PresentationSourceFactory = new TestPresentationSourceFactory(presentationSource); panel.Measure(Size.Infinity); panel.Arrange(new Rect(panel.DesiredSize)); child1.Cursor = Cursors.Help; child2.Cursor = Cursors.Pen; presentationSource.MouseDevice.Activate(); Assert.AreEqual(Cursors.Arrow, presentationSource.MouseDevice.Cursor); presentationSource.MouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 50), 0)); Assert.AreEqual(Cursors.Help, presentationSource.MouseDevice.Cursor); presentationSource.MouseDevice.ProcessRawEvent(new RawMouseEventArgs(new Point(50, 150), 0)); Assert.AreEqual(Cursors.Pen, presentationSource.MouseDevice.Cursor); child2.Cursor = Cursors.Hand; Assert.AreEqual(Cursors.Hand, presentationSource.MouseDevice.Cursor); panel.Cursor = Cursors.Arrow; Assert.AreEqual(Cursors.Hand, presentationSource.MouseDevice.Cursor); panel.ForceCursor = true; Assert.AreEqual(Cursors.Arrow, presentationSource.MouseDevice.Cursor); ((TestApplicationHost)ApplicationHost.Current).PresentationSourceFactory = null; }
private void Print(FileItem item, AutoExportPluginConfig configData) { try { PrintDialog dlg = new PrintDialog(); configData.IsRedy = false; configData.IsError = false; var conf = new PrintPluginViewModel(configData); var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(item.FileName)); outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile); System.Printing.PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket); var PageWidth = (int)capabilities.PageImageableArea.ExtentWidth; var PageHeight = (int)capabilities.PageImageableArea.ExtentHeight; var panel = new StackPanel { Margin = new Thickness(conf.Margin), }; var image = new Image { Source = BitmapLoader.Instance.LoadImage(outfile, PageWidth > PageHeight ? PageWidth : PageHeight, conf.Rotate ? 90 : 0), Width = PageWidth , Height = PageHeight, Stretch = Stretch.Uniform, }; panel.Children.Add(image); panel.UpdateLayout(); panel.Measure(new Size(PageWidth, PageHeight)); panel.Arrange(new Rect(new Point(0, 0), panel.DesiredSize)); panel.UpdateLayout(); dlg.PrintVisual(panel, item.Name); image.Source = null; panel.Children.Clear(); // remove unused file if (outfile != item.FileName) { PhotoUtils.WaitForFile(outfile); File.Delete(outfile); } } catch (Exception exception) { Log.Error("Error print file", exception); configData.IsError = true; configData.Error = exception.Message; } configData.IsRedy = true; }