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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:24:19+00:00 2026-05-16T15:24:19+00:00

I am creating Dynamic Rectangle and adding into StackPanel . I need to add

  • 0

I am creating Dynamic Rectangle and adding into StackPanel. I need to add text to each rectangle. How can I do that?

  • 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-16T15:24:20+00:00Added an answer on May 16, 2026 at 3:24 pm

    A Rectangle doesn’t have any child content, so you will need to put both controls inside of another panel, such as a grid:

    <Grid>
        <Rectangle Stroke="Red" Fill="Blue"/>
        <TextBlock>some text</TextBlock>
    </Grid>
    

    You can also use a Border control, which will take a single child and draw a rectangle around it:

    <Border BorderBrush="Red" BorderThickness="1" Background="Blue">
        <TextBlock>some text</TextBlock>
    </Border>
    

    You say “dynamic rectangle”, so it sounds like you are doing this in code. The equivalent C# would look something like this:

    var grid = new Grid();
    grid.Children.Add(new Rectangle() { Stroke = Brushes.Red, Fill = Brushes.Blue });
    grid.Children.Add(new TextBlock() { Text = "some text" });
    panel.Children.Add(grid);
    // or
    panel.Children.Add(new Border()
    {
        BorderBrush = Brushes.Red,
        BorderThickness = new Thickness(1),
        Background = Brushes.Blue,
        Child = new TextBlock() { Text = "some text" },
    });
    

    But if you want a dynamic list of rectangles, you should probably use an ItemsControl:

    <ItemsControl ItemsSource="{Binding}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="Red" BorderThickness="1" Background="Blue">
                    <TextBlock Text="{Binding Text}"/>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    

    If you set the DataContext to a list of objects, this XAML will create a Border with a TextBlock for each one with the text set to the Text property on the object.

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

Sidebar

Related Questions

I have a scenario that, I am creating dynamic html content and I need
We are creating dynamic text boxes and buttons inside a grid for each row.
I am creating dynamic menus and submenus in php.... Can't know where to start....
I'm creating dynamic templated XAML designs that I would like to convert to PNG
I am creating dynamic TextFields in actionscript 3.0. Like many others, my text disappears
I am creating dynamic text boxes on button click and then showing values on
I need to integrate the functionality of creating dynamic pages (like google sites) to
I'm creating dynamic website with Php and Mysql. So i need insert bangla language
I am currently creating dynamic SSIS packages that import/export and access data between a
i am creating dynamic controls in my asp.net application. Each time i have to

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.