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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:29:12+00:00 2026-05-17T02:29:12+00:00

I have a dockpanel that I dynamically fill using an ItemsControl to populate the

  • 0

I have a dockpanel that I dynamically fill using an ItemsControl to populate the panel. The dockpanel needs the last child from the itemscontrol list to fill the rest of the panel, but it doesn’t seem to happen if I populate it in this fashion… what can I do to get that last item to expand?

snippet of how I have it set up: (note I set the dockpanel background to blue so I could distinguish the populated user controls from the background of the panel)

        <DockPanel Background="Blue" LastChildFill="True" Margin="0">
        <ItemsControl ItemsSource="{Binding Requirements}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <local:TMGrid2View Baseline="{Binding}"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DockPanel>

My current hypothesis as to what is happening is the child-fill is being applied to the itemscontrol instead of the children populated within the itemscontrol. I’ve used setters in the past to specify the child should dock to a side of the panel for instance… but there doesn’t seem to be a child setter option to get it to expand…

  • 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-17T02:29:12+00:00Added an answer on May 17, 2026 at 2:29 am

    What is happening is that your DockPanel is filled with the ItemsControl. So far so good. However, the ItemsControl internally uses a StackPanel which cannot fill vertically (horizontally if set to Orientation=”Horizontal”.

    EDIT: To explain the background is blue… the ItemsControl’s background is default set to null.

    Do you know how many items is in the collection?

    EDIT2: What you need to do when it’s dynamic collection is add the following:

    <ItemsControl ...>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="1"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <!-- rest of ItemsControl properties -->
    </ItemsControl>
    

    The Uniform Grid assigns an equal amount of space to each cell both horizontally and vertically and the ItemsPanel exchanges the standard StackPanel for positioning.

    EDIT3: Working with items of non-equal height… a custom panel:

    public class CustomPanel : StackPanel
    {
        protected override Size ArrangeOverride(Size finalSize)
        {
            var childUIElements = Children.OfType<UIElement>().ToList();
            foreach (var child in childUIElements)
            {
                child.Measure(finalSize);
            }
            double remainingHeight = finalSize.Height - childUIElements.Sum(c => c.DesiredSize.Height);
            if(remainingHeight <= 0)
                return base.ArrangeOverride(finalSize);
    
            double yOffset = 0;
            foreach (var child in childUIElements)
            {
                double height = child.DesiredSize.Height + remainingHeight/childUIElements.Count;
                child.Arrange(new Rect(0,yOffset,finalSize.Width,height));
                yOffset += height;
            }
            return finalSize;
        }
    }
    

    If I haven’t made too many f..-ups that should do a crude version at least. If the items are to large to be contained, it works like a normal stackpanel – if not, it arranges the children to split the remaining space evenly between them. You can adjust it to assign it by ratio if you need it (ie. the larger blocks get more of the remaining space).

    LAST EDIT (I think :-)) You need to put this custom panel inside the ItemsPanelTemplate instead of the UniformGrid I suggested earlier.

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

Sidebar

Related Questions

I have a problem with the DockPanel component. When i resize the panel I
I have a menu with a 'Windows' list that contains all mdi children thanks
I have WPF window that uses a dockpanel and the menu control. I have
I have a recursively defined user control that needs the following properties: there are
I have a WPF that creates buttons dynamically when the form is loaded and
I have a series of dynamically created GridViews that I load. Everything works fine
I have read that I can't have my dockpanel scroll so im looking for
I have a custom control that is derived from TabItem , and I want
In Window1.xaml I have menu and display area: <Menu x:Name=TheMenu Width=Auto Height=25 DockPanel.Dock=Top/> <ItemsControl
I have a DockPanel set up in the DataTemplate of an ItemsControl as below:

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.