CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Getting a stack overflow when trying to make a deep copy that contains a chart

  1. #1
    Join Date
    Sep 2015
    Posts
    1

    Getting a stack overflow when trying to make a deep copy that contains a chart

    I am using .NET 4.0 and VS 2013. I currently have an application that contains several different grids, each representing a different page that needs to be printed. I was able to build a fixed document and print out everything until I needed to add a chart to one of the grids. Now on two of these Grids it collects user data that is then plotted into a chart using the WPF charting toolkit. When I try to clone the grids that contain the charts and try to add them to the the Fix Document I get a stack overflow execption which is triggered by the line of code String gridXaml = XamlWriter.Save(GridName);

    Code:
        
         private void Print_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            pd.UserPageRangeEnabled = true;
    
            document = new FixedDocument();
    
            AddPage(MPEval);
            AddPage(QC);
            AddPage(ID);
            AddPage(AWS);
            AddPage(GAR);
            AddPage(SA);
            AddPage(UAG);
            AddPage(LCD);
            AddPage(RFVolume);
            AddPage(RFSurface);
    
            if (pd.ShowDialog() == true)
            {
    
                DocumentPaginator paginator = document.DocumentPaginator;
    
                if (pd.PageRangeSelection == PageRangeSelection.UserPages)
                {
                    paginator = new PageRangeDocumentPaginator(document.DocumentPaginator, pd.PageRange);
                }
                pd.PrintDocument(paginator, MPSite.Text);
    
            }
        }
    
        private void AddPage(Grid gridName)
        {
            var pageSize = new Size(8.26 * 96, 11.69 * 96); // A4 page, at 96 dpi
            document.DocumentPaginator.PageSize = pageSize;
            // Create FixedPage
            var fixedPage = new FixedPage();
            fixedPage.Width = pageSize.Width;
            fixedPage.Height = pageSize.Height;
            // Add visual, measure/arrange page.
            String gridXaml = XamlWriter.Save(gridName);
            StringReader stringReader = new StringReader(gridXaml);
            XmlReader xmlReader = XmlTextReader.Create(stringReader, new XmlReaderSettings());
            Grid tempGrid = (Grid)XamlReader.Load(xmlReader);
            fixedPage.Children.Add((UIElement)tempGrid);
            fixedPage.Measure(pageSize);
            fixedPage.Arrange(new Rect(new Point(), pageSize));
            fixedPage.UpdateLayout();
    
            // Add page to document
            var pageContent = new PageContent();
            ((IAddChild)pageContent).AddChild(fixedPage);
            document.Pages.Add(pageContent);
        }
    Can anyone please point me in the right direction on how to be able to add these to my fixed document or let me know if I have hit a dead end and need to go another route. Any help is greatly appreciated.

    Thank you,

    Ryan

  2. #2
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Getting a stack overflow when trying to make a deep copy that contains a chart

    Search ICloneable and MemberwiseClone.

    HTH,
    ahoodin
    To keep the plot moving, that's why.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)