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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:02:48+00:00 2026-05-21T09:02:48+00:00

I have created a new Panel called LinearLayout, and Managing the Layouting I am

  • 0

I have created a new Panel called LinearLayout, and Managing the Layouting I am having problem because the field desiredSize is not being set after the MeasureOverride method is called… here is my code:

    protected override Size MeasureOverride(Size availableSize)
    {
        Size panelDesiredSize = new Size();
        if ((this.widthWrap) || (this.heightWrap))
        {
            foreach (UIElement elemento in this.Children)
            {
                System.Diagnostics.Debug.WriteLine("Measure" + ((FrameworkElement)elemento).Name);
                ((FrameworkElement)elemento).Measure(new Size(((FrameworkElement)elemento).Width, ((FrameworkElement)elemento).Height));
                System.Diagnostics.Debug.WriteLine(" child this desireddSIze" + ((FrameworkElement)elemento).DesiredSize);


                if (this.Orientation.Equals(System.Windows.Controls.Orientation.Vertical))
                {
                    if (this.widthWrap)
                    {
                        //the widest element will determine containers width
                        if (panelDesiredSize.Width < ((FrameworkElement)elemento).Width)
                            panelDesiredSize.Width = ((FrameworkElement)elemento).Width;
                    }
                    //the height of the Layout is determine by the sum of all the elment that it cointains
                    if (this.heightWrap)
                        panelDesiredSize.Height += ((FrameworkElement)elemento).Height;
                }
                else
                {
                    if (this.heightWrap)
                    {
                        //The highest will determine the height of the Layout
                        if (panelDesiredSize.Height < ((FrameworkElement)elemento).Height)
                            panelDesiredSize.Height = ((FrameworkElement)elemento).Height;
                    }

                    //The width of the container is the sum of all the elements widths
                    if (this.widthWrap)
                        panelDesiredSize.Width += ((FrameworkElement)elemento).DesiredSize.Width;
                }
            }
        }

        return panelDesiredSize;
    }

I am nesting two linear Layouts: L1 is the parent of L2 and L2 is the parent of 3 buttons.

And the funny thing is that if I write the code below anywhere in the class LinearLayout it works, and the Layout mechanism is called again and it works fine.. but If I call UpdateLayout() nothing happens and the mechanism is not activated(measureoverride ans arrangeoverride are not called)

this.Width = finalSize.Width;
this.Height = finalSize.Height;

Is this a bug? or is just me??? I have been two days already, and it seems to work for the rest of the people …
If anybody can help me I will really appreciate it!
By the way I am working with Silverlight for Windows Phone 7…

  • 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-21T09:02:48+00:00Added an answer on May 21, 2026 at 9:02 am

    The measuring phase will set the DesiredSize property, not the Width/Height properties. The Width/Height properties are used to give an element an explicit size, versus auto-fitting to it’s content (i.e. via the MeasureOverride).

    You shouldn’t be setting the Width/Height based on the results of the measure or arrange phase, as these properties are used by the measure and arrange phases to determine the best size.

    The UpdateLayout isn’t meant to force an element to remeasure/rearrange itself. You would need to use InvalidateMeasure or InvalidateArrange for that task.

    EDIT:

    Also this line of code isn’t really correct:

    ((FrameworkElement)elemento).Measure(new Size(((FrameworkElement)elemento).Width, ((FrameworkElement)elemento).Height));
    

    You should be passing in the availableSize, or whatever size your panel wants to give the element. The Width/Height may not be valid sizes.

    The general rule of thumb is your panel should not touch the Width/Height/MinWidth/MinHeight/etc type properties. It should just pass in an available size, based on the available size it is given. Or you can pass new Size(double.PositiveInfinity, double.PositiveInfinity) when arranging to give an element as much space as it needs.

    In your arrange phase, you can use the element.DesiredSize to determine the element’s arrangement rect.

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

Sidebar

Related Questions

I m new to use ankhSVN and having issues. I have created some new
I am having a bit of problem regarding Swing. I have a JFrame called
We have created a new List View Style that shows thumbnails from a picture
I have created a new solution with a minimal amount of code that represents
I have created a new SharePoint 2007 MOSS Intranet. Our admin people are purchasing
I have created a new method in one of the project's controllers that it
I have created a new table including a column note. The default is varchar(255)
I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
I'm running MOSS 2007 and have created a new site under an existing one
I a xampp setup for php. I have created a new repository at D:/xampp/htdocs/cart

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.