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

  • SEARCH
  • Home
  • 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 9073595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:27:10+00:00 2026-06-16T18:27:10+00:00

I am trying to generate an image of some WPF elements in runtime on

  • 0

I am trying to generate an image of some WPF elements in runtime on a web application. I have had moderate success but there is an issue where child elements will not stretch to fill their parents despite functioning normally if I use the same code in a WPF desktop application. Here’s the code:

Canvas imageCanvas = new Canvas { Width = 1651, Height = 2551, Background = Brushes.White };

Canvas Test = new Canvas();

System.Windows.Shapes.Path Path = new System.Windows.Shapes.Path();
Path.Data = Geometry.Parse("M 0,0 H 287 V 287 H 0 Z");
Path.Stretch = Stretch.Fill;
Path.Stroke = Brushes.Black;
Path.StrokeThickness = 1;

Test.Width = 500;
Test.Height = 500;
Test.Children.Add(Path);

imageCanvas.Children.Add(Test);

Canvas.SetTop(Test, 10);
Canvas.SetLeft(Test, 10);

// Update layout
Size size = new Size(imageCanvas.Width, imageCanvas.Height);
imageCanvas.Measure(size);
imageCanvas.Arrange(new Rect(size));

RenderTargetBitmap bitmapRenderer = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
bitmapRenderer.Render(imageCanvas);

What I expect to see is the square filling up it’s parent canvas but this doesn’t happen. In fact the size of the parent seems to be completely ignored and the path is always the same. Is there anything I can do to force a resize? I thought that the measure and arrange calls on the topmost canvas would do this but apparently not. 🙁

  • 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-06-16T18:27:12+00:00Added an answer on June 16, 2026 at 6:27 pm

    this is a limitation of canvas, and the only way i know to overcome this is to put your Canvas in a “ViewBox” or variation of that, check out this link
    http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.aspx

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

Sidebar

Related Questions

I am trying to generate an image in silverlight but for some reason it
I am trying to Generate Fourier Spectrum of a simple image. But what I
Im trying to generate an image, and have found UIGraphicsBeginImageContext() in the Apple docs
currently i'm trying to use imagick to generate some images without saving them on
I'm trying to generate a report of the activities that users have done within
I have been trying to generate report as per age differences of different months
i am trying to generate a checkbox list feeded by some records from a
I'm trying to generate a vector graphic from an area in a bitmap image,
I am trying to build a layout dynamically which display some text and image
I am trying to generate a text image. So I create a new font:

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.