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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:59:17+00:00 2026-06-01T01:59:17+00:00

I need a control having these features: It should be possible use it in

  • 0

I need a control having these features:

  1. It should be possible use it in xaml to design.
  2. It should be able to hold multiple child elements of a single type. Say Button for example.
  3. These child elements will have fixed dimensions. The control has to figure out what is the maximum number of children that it can completely display vertically and horizontally (Can’t show any child partially). And only display those children but keep the non-visible children for later use. – I think I can get this requirement done with a Grid.
  4. Should be possible to animate these child elements – I guess this is not an issue.

I tried to write a custom control to do this. I inherited from a Grid and having seen that Grid implements IAddChild I thought I could catch elements being added if I overrode AddChild. But now I find that there is no implementation for AddChild in Grid either! So it seems I can’t do it like that. Where should I start?

EDIT: Thanks to Alan’s pointers, I got it working…

public class AutoLayoutingPanel : Panel
{
    protected override Size MeasureOverride(Size availableSize)
    {
        Size size = new Size();
        size.Height = double.MaxValue;
        size.Width = double.MaxValue;

        foreach (UIElement child in Children)
        {
            child.Measure(size);
            size.Height += child.DesiredSize.Height;
            size.Width += child.DesiredSize.Width;
        }

        return availableSize;
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        ArrangeGrid(finalSize);
        return finalSize;
    }

    private void ArrangeGrid(Size finalSize)
    {
        foreach (UIElement child in Children)
        {
            child.Visibility = Visibility.Hidden;
        }

        Size maxCellSize = new Size();

        foreach (UIElement child in Children)
        {
            maxCellSize.Height = Math.Max(child.DesiredSize.Height, maxCellSize.Height);
            maxCellSize.Width = Math.Max(child.DesiredSize.Width, maxCellSize.Width);
        }

        int rowCount = (int)Math.Floor(finalSize.Height / maxCellSize.Height);
        int colCount = (int)Math.Floor(finalSize.Width / maxCellSize.Width);

        int row = 0, col = 0;
        foreach (UIElement child in Children)
        {
            if (row < rowCount && col < colCount)
            {
                Rect pos = new Rect(col * maxCellSize.Width, row * maxCellSize.Height, maxCellSize.Width, maxCellSize.Height);
                child.Visibility = System.Windows.Visibility.Visible;
                child.Arrange(pos);
            }
            else
            {
                break;
            }

            if (++row >= rowCount)
            {
                row = 0;
                ++col;
            }
        }
    }
}
  • 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-01T01:59:18+00:00Added an answer on June 1, 2026 at 1:59 am

    I think you’ll need to create a custom layout panel instead of trying to inherit from Grid (as to the IAddChild interface, it is implemented using EIMI and is therefore neither visible nor overridable from the outside). Here is a good starting point.

    (Also, you’ll need to think about how you want to restrict the type of child controls that your control can hold. Using generics would be an option, but I have doubts about XAML generics support.)

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

Sidebar

Related Questions

I need to create control to draw border around its child. So, I have
I need to control inbound and outbound traffic to/from a linux box from within
I need a control that can list data in 3 columns, I want to
I need GUI control for audio file presentation. The language is not very important
We are using Grails with a legacy database and we need to control how
I need .NET UI control that acts as a designer/editor window similar to what
I need a WinForms control that will allow me to add control such as
I am making a custom control I need to add some default keybindings, microsoft
I've to create an activeX control that need to run without any prerequisit (like
I'm having to design & develop UI for a Point of Sale (POS) system.

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.