Smrf.NodeXL.ExcelTemplate.GraphImageCompositor.RestoreNodeXLControl C# (CSharp) Method

RestoreNodeXLControl() public method

public RestoreNodeXLControl ( ) : void
return void
    RestoreNodeXLControl()
    {
        AssertValid();

        // Reconnect the NodeXLControl to its original parent and reset the
        // size to Auto.

        m_oGrid.Children.Remove(m_oNodeXLControl);
        m_oNodeXLControl.Width = Double.NaN;
        m_oNodeXLControl.Height = Double.NaN;

        m_oGraphImageCenterer.RestoreCenter();
        m_oGraphImageScaler.RestoreGraphScale();

        m_oParentPanel.Children.Insert(m_iChildIndex, m_oNodeXLControl);

        // The graph may have shrunk, and even though it will be expanded to
        // its original dimensions when UpdateLayout() is called below, the
        // layout may have lost "resolution" and the results may be poor.
        //
        // Fix this by restoring the original layout and redrawing the graph.

        m_oNodeXLControl.UpdateLayout();
        m_oLayoutSaver.RestoreLayout();
        m_oNodeXLControl.DrawGraph(false);
    }

Usage Example

コード例 #1
0
        SaveObject
        (
            Object oObject,
            String sFileName
        )
        {
            Debug.Assert(oObject is GraphImageInfo);
            Debug.Assert(!String.IsNullOrEmpty(sFileName));

            GraphImageInfo oGraphImageInfo = (GraphImageInfo)oObject;
            Int32          iWidth          = oGraphImageInfo.Width;
            Int32          iHeight         = oGraphImageInfo.Height;

            GraphImageCompositor oGraphImageCompositor =
                new GraphImageCompositor(oGraphImageInfo.NodeXLControl);

            UIElement oCompositeElement = null;

            try
            {
                if (m_oSaveFileDialog.FilterIndex <=
                    SaveableImageFormats.ImageFormats.Length)
                {
                    // The graph must be saved as a bitmap.

                    oCompositeElement = oGraphImageCompositor.Composite(
                        iWidth, iHeight, oGraphImageInfo.HeaderText,
                        oGraphImageInfo.FooterText,
                        oGraphImageInfo.HeaderFooterFont,
                        oGraphImageInfo.LegendControls);

                    System.Drawing.Bitmap oBitmap = WpfGraphicsUtil.VisualToBitmap(
                        oCompositeElement, iWidth, iHeight);

                    base.SaveObject(oBitmap, sFileName);
                    oBitmap.Dispose();
                }
                else
                {
                    // The graph must be saved as an XPS.

                    Double documentWidth  = ToWpsUnits(iWidth);
                    Double documentHeight = ToWpsUnits(iHeight);

                    oCompositeElement = oGraphImageCompositor.Composite(
                        documentWidth, documentHeight, oGraphImageInfo.HeaderText,
                        oGraphImageInfo.FooterText,
                        oGraphImageInfo.HeaderFooterFont,
                        oGraphImageInfo.LegendControls);

                    Size oDocumentSize      = new Size(documentWidth, documentHeight);
                    Rect oDocumentRectangle = new Rect(new Point(), oDocumentSize);

                    FixedDocument oFixedDocument = new FixedDocument();
                    oFixedDocument.DocumentPaginator.PageSize = oDocumentSize;
                    PageContent oPageContent = new PageContent();

                    FixedPage oFixedPage = new FixedPage();
                    oFixedPage.Width  = documentWidth;
                    oFixedPage.Height = documentHeight;

                    oFixedPage.Children.Add(oCompositeElement);

                    ((System.Windows.Markup.IAddChild)oPageContent).AddChild(
                        oFixedPage);

                    oFixedDocument.Pages.Add(oPageContent);

                    XpsDocument oXpsDocument = new XpsDocument(sFileName,
                                                               FileAccess.Write);

                    XpsDocumentWriter oXpsDocumentWriter =
                        XpsDocument.CreateXpsDocumentWriter(oXpsDocument);

                    oXpsDocumentWriter.Write(oFixedDocument);
                    oXpsDocument.Close();
                }
            }
            finally
            {
                if (oCompositeElement != null)
                {
                    oGraphImageCompositor.RestoreNodeXLControl();
                }
            }
        }
All Usage Examples Of Smrf.NodeXL.ExcelTemplate.GraphImageCompositor::RestoreNodeXLControl