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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:31:23+00:00 2026-06-06T05:31:23+00:00

I have a wrap panel that will contain a variable amount of controls. I

  • 0

I have a wrap panel that will contain a variable amount of controls.

I want the orientation to be vertical (as objects within will have a fixed width but variable height).

But the issue I’m having is that when a scrollbar is present the height is inifinite so the items never wrap onto the second column. The scrollbar is necessary as there will frequently be more objects than it’s possible to fit on one screen.
I can stop this by setting a fixed height, but this isn’t an acceptable solution as a reasonable fixed height will differ for each selection.

Essentially I’d like a WrapPanel whose height changes dynamically based on the width of the panel and the amount of items contained within.

To illustrate:

If the panel is wide enough to show 3 columns it will:

| 1 5 9 |

| 2 6 – |

| 3 7 – | Height=4

| 4 8 – |

But if the user changes the size of the window to the point where it can only accomodate 2 columns the height will increase:

| 1 6 |

| 2 7 |

| 3 8 | Height = 5

| 4 9 |

| 5 – |

Also, I’m not sure how feasible this is but I would ideally like the order the items horizonatally but keep the orientation vertical, so they’d be ordered:

| 1 2 3 |

| 4 5 6 |

| 7 8 9 |

Could anyone tell me how to go about getting started with this? I’m assuming it’s possible with a custom implementation of the WrapPanel, but I’m slightly confused how to get started.

Thanks,

  • 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-06T05:31:25+00:00Added an answer on June 6, 2026 at 5:31 am

    Manged to achieve what I needed with the following code:

    public class InvertedWrapPanel : WrapPanel
    {
        private int itemsPerRow = 0;
    
        protected override Size MeasureOverride(Size availableSize)
        {
            if (Orientation == Orientation.Horizontal)
            {
                return base.MeasureOverride(availableSize);
            }
            else //Orientation is vertical
            {
                double w = availableSize.Width;
    
                double maxChildWidth = 0;
    
                foreach (UIElement child in Children)
                {
                    //Get the current childs desired size parameters
                    child.Measure(availableSize);
    
                    //Store off the maximum child width
                    if (child.DesiredSize.Width > maxChildWidth)
                        maxChildWidth = child.DesiredSize.Width;
                }
    
                //See how many items we can fit in a row
                itemsPerRow = Convert.ToInt32(Math.Floor(w / maxChildWidth));
    
                return base.MeasureOverride(availableSize);
            }
        }
    
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (Orientation == Orientation.Horizontal)
            {
                return base.ArrangeOverride(finalSize);
            }
            else //Orientation is vertical
            {
                double currentX = 0;
                double currentY = 0;
    
                int col = 0;
    
                double lastX = 0;
                double lastWidth = 0;
    
                //Arrays to store differing column heights
                double[] lastY = new double[itemsPerRow];
                double[] lastHeight = new double[itemsPerRow];
    
                double[] colHeights = new double[itemsPerRow];
    
                foreach (UIElement child in Children)
                {
                    //If we've reached the end of a row
                    if (col >= itemsPerRow)
                    {
                        col = 0;
                        currentX = 0; //reset the x-coordinate for first column
                    }
                    else
                        currentX = lastX + lastWidth; //Increase the x-coordinate
    
                    //Increase the y-coordinates for the current column
                    currentY = lastY[col] + lastHeight[col];
    
                    //Draw the element
                    child.Arrange(new Rect(currentX, currentY, child.DesiredSize.Width, child.DesiredSize.Height));
    
                    //Store off the current child's parameters
                    lastX = currentX;
                    lastWidth = child.DesiredSize.Width;
    
                    lastY[col] = currentY;
                    lastHeight[col] = child.DesiredSize.Height;
    
                    colHeights[col] += child.DesiredSize.Height;
    
                    col++;
                }
    
                //Set the height of the panel to the max column height.
                //Otherwise scroll bar will set height to infinity.
                double maxHeight = 0;
    
                foreach (double d in colHeights)
                {
                    if (d > maxHeight)
                        maxHeight = d;
                }
    
                base.Height = maxHeight;
    
                return finalSize;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of controls that I am displaying via a WrapPanel and
Do I have to wrap all my IDisposable objects in using(){} statements, even if
I am trying to create a user control within a WPF application that will
I have a wrap panel full of rectangles, when you mouse over a rectangle
I have a Panel which is a contentPane of a JDialog . That Panel
In silverlight 2.0. I have some content that i want to scroll vertically and
I have a UserControl (XAML below) that has a ListBox that I want to
Say we have an overlay DHTML panel on a web page that contains two
Can I select a block of code and have IntelliJ wrap it with a
I have set linebreak and wrap. The document looks great on my screen but

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.