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 8478231
In Process

The Archive Base Latest Questions

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

I have a Canvas named mainCanvas and I’m programatically adding a ScrollViewer and a

  • 0

I have a Canvas named mainCanvas and I’m programatically adding a ScrollViewer and a StackPanel to it in order of

…mainCanvas

……scrollView

………pnl

………… (more stacked controls)

I’m attempting to get my StackPanel to auto size to the mainCanvas size and allow scrolling when it’s too large. Code so far is below

mainCanvas.Children.Clear();

// Create the container
ScrollViewer scrollView = new ScrollViewer();
scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollView.CanContentScroll = true;
scrollView.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
scrollView.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

StackPanel pnl = new StackPanel();
//pnl.Height = 500; //Works and allows scrolling but doesn't resize
pnl.Height = Double.NaN; //(Double.NaN is Auto) Doesn't Work - StackPanel overflows parent window

pnl.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
pnl.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;


scrollView.Content = pnl;

// Add the ScrollView and StackPanel to Parent Window
mainCanvas.Children.Add(scrollView);

Unfortunately, the StackPanel doesn’t fit to the parent and doesn’t autosize.

mainCanvas already exists in XAML with settings:

Width= “Auto”

Height= “Auto”

HorizontalAlignment = “Stretch”

VerticalAlignment = “Stretch”

I can get things semi-working by using pnl.Height = 500; which shows me the scrollbar does work if the Stackpanel height is restricted. But this is just manually fitting the height to the full screen size and so doesn’t autosize when resizing the app.

I hoped setting pnl.Height = Double.NaN; to auto and V/H adjustment to Stretch would work but the StackPanel still overlaps all controls to it’s maximum size.

Can anyone point me in the right direction to get my StackPanel to fit the parent mainCanvas and autosize when I resize either the parent and/or the main app window with scrolling?

Thank you

  • 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-10T18:41:22+00:00Added an answer on June 10, 2026 at 6:41 pm

    I believe Canvas is for absolute positioning only. Using a Grid as your panel instead would probably give you the desired result.

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

Sidebar

Related Questions

I have a Canvas element, contained within a ScrollViewer, which I'm zooming using ScaleTransform.
I have a Custom Canvas(DesignerCanvas), user can add some controls to this canvas. Before
I have a noob question =P How can I programatically add a canvas to
I have a ListBox with a ItemsPanelTemplate of Canvas. I know the ScrollViewer will
I have a movieclip instance named 'placeholder' on the canvas, and I want to
I have a Silverlight user control that has several canvas controls within a Stack
I have a canvas in xaml defined as following. However adding a rectangle in
I have a canvas element positioned absolutely over a Flash object of the same
I have a Canvas with a Rectangle : <Canvas> <Rettangle/> </Canvas> And I want
I have a canvas and I use jCanva (http://calebevans.me/projects/jcanvas/docs.php?p=layers)s to create circles with events.

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.