Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 683161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:40:36+00:00 2026-05-14T01:40:36+00:00

I have searched through many times but have not seen this before. Probably really

  • 0

I have searched through many times but have not seen this before. Probably really simple question but can’t wrap my head around it.

Wrote a VSTO add-in for Excel that draws a Grid dynamically. Then launches a new window and replaces the contents of the Canvas with the generated Grid. The problem is with printing. When I call the print procedure the canvas.height and canvas.width returned is the old value prior to replacing it with the grid.

Sample:

string="<Grid Name=\"CanvasGrid\"  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">..Lots of stuff..</Grid>";

// Launch new window and replace the Canvas element

WpfUserControl newWindow = new WpfUserControl();                            
newWindow.Show();


//To test
MessageBox.Show(myCanvas.ActualWidth.ToString());
//return 894
Grid testGrid = myCanvas.FindName("CanvasGrid") as Grid;
MessageBox.Show("Grid " + testGrid.ActualWidth.ToString());
//return 234


StringReader stringReader = new StringReader(LssAllcChrt);
XmlReader xmlReader = XmlReader.Create(stringReader);

Canvas myCanvas = newWindow.FindName("GrphCnvs") as Canvas;
myCanvas.Children.Clear();
myCanvas.Children.Add((UIElement)XamlReader.Load(xmlReader));

//To test
MessageBox.Show(myCanvas.ActualWidth.ToString());
//return 894 but should be much larger the Grid spans all three of my screens
Grid testGrid = myCanvas.FindName("CanvasGrid") as Grid;
MessageBox.Show("Grid " + testGrid.ActualWidth.ToString());
//return 234 but should be much larger the Grid spans all three of my screens

//Run code from WpfUserControl.cs after it loads from button click
Grid testGrid = canvas.FindName("CanvasGrid") as Grid;
MessageBox.Show("Grid " + testGrid.ActualWidth.ToString());
//return 234 but should be much larger the Grid spans all three of my screens

So basically I have no way of telling what my new width and height are.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:40:36+00:00Added an answer on May 14, 2026 at 1:40 am

    Ok here is what I did to fix the issue.

    Basically I was looking to print the grid I created if it went out of the visual bonds. I changed the new window to TabControl and TabItems because it was a new requirement (Yeah me (sarcasm)). So what I did was to reference the selected TabItem, reference the ScrollViewer as the only content in the tabitem and reference the Grid as a FrameworkElement:

    TabItem ti = GBtabControl.SelectedItem as TabItem;
    ScrollViewer sc = ti.Content as ScrollViewer;
    FrameworkElement element = sc.Content as FrameworkElement;
    

    The element gives the correct width and height and I can now print and export the chart as a png file.

    Thanks for the support

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realise this may be a duplicate, but I have searched through many forums
I've searched through SO quite a bit for this, but I haven't seen a
I have searched for a general solution to this but only find answers to
I have searched through the google and also joomla forums but didn't got what
Not a great title but I'm looking more for some guidance, have searched quite
i really need some help on this. I searched the internet but couldn't find
I have searched this site for an answer and found many responses to unsigned/signed
I have seen many related questions but didn't find any answer. I have successfully
I have searched through the forum for my answer, But all the calendar questions
I realize this is a popular topic, and I've searched through many posts here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.