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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:29:07+00:00 2026-06-16T01:29:07+00:00

I need to fill an panel with clickable button-based cells that looks like this:

  • 0

I need to fill an panel with clickable button-based cells that looks like this:

with rectangle

this has done with rectangles:

<ItemsControl ItemsSource="{Binding Path=Cells}">
      <ItemsControl.ItemTemplate>
          <DataTemplate>
              <Rectangle>
                  <Rectangle.Fill>
                      <SolidColorBrush Color="Red"></SolidColorBrush>
                  </Rectangle.Fill>
              </Rectangle>
          </DataTemplate>
      </ItemsControl.ItemTemplate>
      <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
               <commonControls:UniformGrid ElementsGap="5" HorizontalCount="{Binding Path=CellsInRow}" />
          </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
  </ItemsControl>

but I need to do it with buttons. I’m trying that:

<ItemsControl ItemsSource="{Binding Path=Cells}">
      <ItemsControl.ItemTemplate>
          <DataTemplate>
              <Button>
                  <Button.Background>
                      <SolidColorBrush Color="Red"></SolidColorBrush>
                  </Button.Background>
              </Button>
          </DataTemplate>
      </ItemsControl.ItemTemplate>
      <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
               <commonControls:UniformGrid ElementsGap="5" HorizontalCount="{Binding Path=CellsInRow}" />
          </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
  </ItemsControl>

But it seems like that:

with button

How i can do cells from first image with buttons?

Code of UniformGrid below:

 public class UniformGrid : Panel
{
    public static readonly DependencyProperty HorizontalCountProperty =
        DependencyProperty.Register("HorizontalCount", typeof (int), typeof (UniformGrid),
                                    new PropertyMetadata(default(int)));

    public int HorizontalCount
    {
        get { return (int) GetValue(HorizontalCountProperty); }
        set { SetValue(HorizontalCountProperty, value); }
    }

    public static readonly DependencyProperty ElementsGapProperty =
        DependencyProperty.Register("ElementsGap", typeof (double), typeof (UniformGrid),
                                    new PropertyMetadata(default(double)));

    public double ElementsGap
    {
        get { return (double) GetValue(ElementsGapProperty); }
        set { SetValue(ElementsGapProperty, value); }
    }

    protected override Size MeasureOverride(Size availableSize)
    {
        return new Size();
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        if (Children != null && Children.Count != 0)
        {
            var squareSideForElement = (finalSize.Width - (HorizontalCount - 1)*ElementsGap)/HorizontalCount;
            var sizeOfElement = new Size(squareSideForElement, squareSideForElement);
            for (var i = 0; i < Children.Count; i++)
            {
                var rowIndex = i%HorizontalCount;
                var columnIndex = i/HorizontalCount;
                var resultPoint = new Point
                    {
                        X = rowIndex*(squareSideForElement + ElementsGap),
                        Y = columnIndex*(squareSideForElement + ElementsGap)
                    };
                Children[i].Arrange(new Rect(resultPoint, sizeOfElement));

            }

        }
        return finalSize;
    }
}
  • 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-16T01:29:08+00:00Added an answer on June 16, 2026 at 1:29 am

    Your MeasureOverride must call Measure on each child. Please read the Remarks section in MeasureOverride, especially the following note:

    Elements should call Measure on each child during this process,
    otherwise the child elements will not be correctly sized or arranged

    You should at least do this:

    protected override Size MeasureOverride(Size availableSize)
    {
        foreach (UIElement element in InternalChildren)
        {
            element.Measure(availableSize);
        }
    
        return new Size();
    }
    

    If you want to make sure that every child calculates its maximum preferred size, you could pass an infinite width and height to Measure:

    protected override Size MeasureOverride(Size availableSize)
    {
        availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
    
        foreach (UIElement element in InternalChildren)
        {
            element.Measure(availableSize);
        }
    
        return new Size();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to fill a rectangle with a black to white (transparent) gradient. However,
I need to create a fading background image that stretches to fill the browser.
I have two fields that need to multiply each other and fill a third
I have a combobox in a dialog box form. I need to fill this
i need to fill a listbox with items one by one like the list
I need to fill textboxes depending on the item selected in a combobox. I
For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1);
I have a List[Option[MyClass]] with None in random positions and I need to 'fill'
Starting with an empty dataframe, I need to fill the dataframe as follows: A
I need to know the information when i fill the form and then submit

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.