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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:41:59+00:00 2026-06-12T04:41:59+00:00

I’d like to convert the following XAML sample code into its C# equivalent: <Grid>

  • 0

I’d like to convert the following XAML sample code into its C# equivalent:

<Grid>
<Grid.ColumnDefinitions>
    <ColumnDefinition/>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition/>
</Grid.ColumnDefinitions>

<!-- Sub-grid on left -->
<Grid Grid.Column="0">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <Label Content="Left, Row 0" Background="Azure" Grid.Row="0"/>
    <Label Content="Left, Row 2" Background="Lavender" Grid.Row="2"/>
    <GridSplitter Grid.Row="1" Height="8" Background="DarkSlateBlue"
        HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</Grid>

<!-- Sub-grid on right -->
<Grid Grid.Column="2">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <Label Content="Right, Row 0" Background="Moccasin" Grid.Row="0"/>
    <Label Content="Right, Row 2" Background="Honeydew" Grid.Row="2"/>
    <GridSplitter Grid.Row="1" Height="8" Background="DarkSlateBlue"
        HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</Grid>

<!-- Splitter between left/right sub-grids -->
<GridSplitter Grid.Column ="1" Width="8" Background="DarkSlateBlue"
    VerticalAlignment="Stretch" HorizontalAlignment="Center"/>

This is my code so far:

    Grid DynamicGrid = new Grid();
ColumnDefinition gridColDef0 = new ColumnDefinition();
ColumnDefinition gridColDef1 = new ColumnDefinition();
gridColDef1.Width = new GridLength(1, GridUnitType.Auto);
ColumnDefinition gridColDef2 = new ColumnDefinition();
DynamicGrid.ColumnDefinitions.Add(gridColDef0);
DynamicGrid.ColumnDefinitions.Add(gridColDef1);
DynamicGrid.ColumnDefinitions.Add(gridColDef2);
RowDefinition gridRowDef0 = new RowDefinition();
RowDefinition gridRowDef1 = new RowDefinition();
gridRowDef1.Height = new GridLength(1, GridUnitType.Auto);
RowDefinition gridRowDef2 = new RowDefinition();

But I don’t know how to add the grid row definitions to column 0. I’d have expected something along the lines of DynamicGrid.Columns[0].RowDefinitions.Add, but I haven’t found such a thing. Can you help me? Thanks!

Edit: For future reference, here’s the equivalent C# code. Mind you, it can be optimized!

private void CreateDynamicWPFGrid()
    {
        // Create the Grid
        Grid dynamicGrid = new Grid();

        ColumnDefinition gridColDef0 = new ColumnDefinition();
        ColumnDefinition gridColDef1 = new ColumnDefinition();
        gridColDef1.Width = new GridLength(1, GridUnitType.Auto);
        ColumnDefinition gridColDef2 = new ColumnDefinition();

        dynamicGrid.ColumnDefinitions.Add(gridColDef0);
        dynamicGrid.ColumnDefinitions.Add(gridColDef1);
        dynamicGrid.ColumnDefinitions.Add(gridColDef2);

        // Sub-grid on left.
        {
            Grid leftSubGrid = new Grid();

            RowDefinition gridRowDef0 = new RowDefinition();
            RowDefinition gridRowDef1 = new RowDefinition();
            gridRowDef1.Height = new GridLength(1, GridUnitType.Auto);
            RowDefinition gridRowDef2 = new RowDefinition();

            leftSubGrid.RowDefinitions.Add(gridRowDef0);
            leftSubGrid.RowDefinitions.Add(gridRowDef1);
            leftSubGrid.RowDefinitions.Add(gridRowDef2);

            Label label;
            label = new Label();
            label.Content = "Left, Row 0";
            label.Background = new SolidColorBrush(Colors.Azure);
            Grid.SetRow(label, 0);
            leftSubGrid.Children.Add(label);

            label = new Label();
            label.Content = "Left, Row 2";
            label.Background = new SolidColorBrush(Colors.Lavender);
            Grid.SetRow(label, 2);
            leftSubGrid.Children.Add(label);

            GridSplitter gridSplitter = new GridSplitter();
            gridSplitter.Height = 8;
            gridSplitter.Background = new SolidColorBrush(Colors.DarkSlateBlue);
            gridSplitter.HorizontalAlignment = HorizontalAlignment.Stretch;
            gridSplitter.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(gridSplitter, 1);
            leftSubGrid.Children.Add(gridSplitter);

            Grid.SetColumn(leftSubGrid, 0);
            dynamicGrid.Children.Add(leftSubGrid);
        }

        // Sub-grid on right.
        {
            Grid rightSubGrid = new Grid();

            RowDefinition gridRowDef0 = new RowDefinition();
            RowDefinition gridRowDef1 = new RowDefinition();
            gridRowDef1.Height = new GridLength(1, GridUnitType.Auto);
            RowDefinition gridRowDef2 = new RowDefinition();

            rightSubGrid.RowDefinitions.Add(gridRowDef0);
            rightSubGrid.RowDefinitions.Add(gridRowDef1);
            rightSubGrid.RowDefinitions.Add(gridRowDef2);

            Label label;
            label = new Label();
            label.Content = "Left, Row 0";
            label.Background = new SolidColorBrush(Colors.Moccasin);
            Grid.SetRow(label, 0);
            rightSubGrid.Children.Add(label);

            label = new Label();
            label.Content = "Left, Row 2";
            label.Background = new SolidColorBrush(Colors.Honeydew);
            Grid.SetRow(label, 2);
            rightSubGrid.Children.Add(label);

            GridSplitter gridSplitter = new GridSplitter();
            gridSplitter.Height = 8;
            gridSplitter.Background = new SolidColorBrush(Colors.DarkSlateBlue);
            gridSplitter.HorizontalAlignment = HorizontalAlignment.Stretch;
            gridSplitter.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(gridSplitter, 1);
            rightSubGrid.Children.Add(gridSplitter);

            Grid.SetColumn(rightSubGrid, 2);
            dynamicGrid.Children.Add(rightSubGrid);
        }

        {
            GridSplitter gridSplitter = new GridSplitter();
            gridSplitter.Width = 8;
            gridSplitter.Background = new SolidColorBrush(Colors.DarkSlateBlue);
            gridSplitter.HorizontalAlignment = HorizontalAlignment.Center;
            gridSplitter.VerticalAlignment = VerticalAlignment.Stretch;
            Grid.SetColumn(gridSplitter, 1);
            dynamicGrid.Children.Add(gridSplitter);
        }

        // Display grid into a Window
        Content = dynamicGrid;
    }
  • 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-12T04:42:01+00:00Added an answer on June 12, 2026 at 4:42 am

    Your XAML represents a grid of grids — i.e. the outer grid has one row with three columns. each “cell” contains a single grid with three rows each, and a single column.

    Your code version only has a single Grid.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:

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.