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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:53:24+00:00 2026-06-03T11:53:24+00:00

How can I generate layout (XAML) programmatically? Let say I have some kind of

  • 0

How can I generate layout (XAML) programmatically?

Let say I have some kind of loop. And after each I want to generate this with the values I got:

                <Grid Height="150" Name="grid1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="200" />
                    </Grid.ColumnDefinitions>
                    <Image Height="150" Name="image1" Stretch="Fill" Width="200" Grid.Column="1" Source="/Ilm;component/Images/testicon.png" HorizontalAlignment="Right" VerticalAlignment="Top" />
                    <TextBlock Height="51" Name="textBlock1" Text="Paris" Margin="12,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="40" />
                    <TextBlock FontSize="40" Height="51" HorizontalAlignment="Left" Margin="13,75,0,0" Name="textBlock2" Text="19°C" VerticalAlignment="Top" />
                </Grid>
  • 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-03T11:53:26+00:00Added an answer on June 3, 2026 at 11:53 am

    To add a new row to the grid, you will need to add a new row definition and then add the new controls. It will be similiar to the following logic:

    rowNumber = 0; // Set the current row that you are adding 
    grid1.RowDefinitions.Add(new RowDefinition());
    
    Image img = new Image();
    img.Height = 150;
    img.Name = "image1";
    img.Stretch = Stretch.Fill;
    img.Width = 200;
    img.HorizontalAlignment = HorizontalAlignment.Right;
    img.VerticalAlignment = VerticalAlignment.Top;
    // Set your image properties
    img.SetValue(Grid.RowProperty, rowNumber);
    img.SetValue(Grid.ColumnProperty, 1);
    grid1.Children.Add(img);
    
    TextBlock tb1 = new TextBlock();
    // Set your text block properties
    tb1.SetValue(Grid.RowProperty, rowNumber);
    tb1.SetValue(Grid.ColumnProperty, 0);
    grid1.Children.Add(tb1);
    
    TextBlock tb2 = new TextBlock();
    // Set your text block properties
    tb2.SetValue(Grid.RowProperty, rowNumber);
    tb2.SetValue(Grid.ColumnProperty, 0);
    grid1.Children.Add(tb2);
    

    You will need to put the properties that you want to set where I have the comment and also provided the correct row number (zero based).

    To add the entire thing…

    Grid grid1 = new Grid();
    grid1.Height = 150;
    grid1.Name = "grid1";
    parentControl.Children.Add(grid1); // Note: parentControl is whatever control you are added this to
    grid1.ColumnDefinitions.Add(new ColumnDefinition());
    grid1.ColumnDefinitions.Add(new ColumnDefinition { Width = 200});
    
    // From here insert the code for adding a row that is provided above
    

    And that’s it. You’ll just need to fill in the properties I haven’t provided. Remember that your variable parentControl will be different. You haven’t provided what control you are adding these into, so it is unclear what that would be.

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

Sidebar

Related Questions

I want to generate html layout with areas (divs, spans) that can be shown/hidden
Let's say I have a list of products. I want to display a list
I have a HQL query that can generate either an IList of results, or
I want to create an XSD which can generate the following XML. <note> <email:to>abc@def.com</email:to>
i'm showing the image of the desired Layout which i want to generate i'm
I have to generate the following layout for a web site with all elements
I want to use the 960 grid system to generate the layout for my
what I want to achieve is this: As you can see there is are
I can generate my models and schema.yml file based on an existing database. But
How i can generate code using all cores on my computer in debug mode?

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.