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

The Archive Base Latest Questions

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

I need to write a C# WPF program in order to let the user

  • 0

I need to write a C# WPF program in order to let the user individually modify the width and height of a grid using the mouse. After some reading, I’ve found out that WPF featues the GridSplitter control, which seems to be a possible solution for my problem. So far, this is my approach:

private const int NumCols = 5;
    private const int NumRows = 7;

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

        for (int i = 0; i < NumCols - 1; ++i )
        {
            // Define 2 * (NumCols - 1) columns. For every two columns, the first one will hold a label
            // whereas the second one will hold a vertical splitter.

            var gridColDefA = new ColumnDefinition();
            // The gridColDefB is for the splitter.
            var gridColDefB = new ColumnDefinition();
            gridColDefB.Width = new GridLength(1, GridUnitType.Auto);

            dynamicGrid.ColumnDefinitions.Add(gridColDefA);
            dynamicGrid.ColumnDefinitions.Add(gridColDefB);
        }
        {
            // The last column only needs a cell for holding a label. No splitter whatsoever.
            var gridColDef = new ColumnDefinition();
            dynamicGrid.ColumnDefinitions.Add(gridColDef);
        }

        for (int j = 0; j < NumRows - 1; ++j)
        {
            var gridRowDefA = new RowDefinition();
            var gridRowDefB = new RowDefinition();
            // The gridRowDefB is for the splitter.
            gridRowDefB.Height = new GridLength(1, GridUnitType.Auto);

            dynamicGrid.RowDefinitions.Add(gridRowDefA);
            dynamicGrid.RowDefinitions.Add(gridRowDefB);
        }
        {
            // The last row only needs a cell for holding a label. No splitter whatsoever.
            var gridRowDef = new RowDefinition();
            dynamicGrid.RowDefinitions.Add(gridRowDef);
        }

        for (int i = 0; i < NumCols - 1; ++i )
        {
            for(int j = 0; j < NumRows - 1; ++j )
            {
                // Insert the label.
                var label = new Label();
                label.Content = "C" + i + "-R" + j;
                label.Background = new SolidColorBrush(Colors.Azure);
                Grid.SetColumn(label, 2 * i);
                Grid.SetRow(label, 2 * j);
                dynamicGrid.Children.Add(label);

                // Insert the horizontal splitter.
                var horizontalGridSplitter = new GridSplitter();
                horizontalGridSplitter.Height = 1;
                horizontalGridSplitter.Background = new SolidColorBrush(Colors.DarkSlateBlue);
                horizontalGridSplitter.HorizontalAlignment = HorizontalAlignment.Stretch;
                horizontalGridSplitter.VerticalAlignment = VerticalAlignment.Center;
                Grid.SetColumn(horizontalGridSplitter, 2 * i );
                Grid.SetRow(horizontalGridSplitter, 2 * j + 1);
                Grid.SetRowSpan(horizontalGridSplitter, 1);
                Grid.SetColumnSpan(horizontalGridSplitter, 1);
                dynamicGrid.Children.Add(horizontalGridSplitter);

                // Insert the vertical splitter.
                var verticalGridSplitter = new GridSplitter();
                verticalGridSplitter.Width = 1;
                verticalGridSplitter.Background = new SolidColorBrush(Colors.DarkSlateBlue);
                verticalGridSplitter.HorizontalAlignment = HorizontalAlignment.Center;
                verticalGridSplitter.VerticalAlignment = VerticalAlignment.Stretch;
                Grid.SetColumn(verticalGridSplitter, 2 * i + 1);
                Grid.SetRow(verticalGridSplitter, 2 * j + 1);
                Grid.SetRowSpan(verticalGridSplitter, 1);
                Grid.SetColumnSpan(verticalGridSplitter, 1);
                dynamicGrid.Children.Add(verticalGridSplitter);
            }
        }

        // Display grid into a Window
        Content = dynamicGrid;
    }

The output I’m getting is as follows:

Default output

Notice that I’m only able to resize the rows (don’t know why the vertical splitters don’t show up) and, for some reason, when I grab a horizontal splitter it resizes the whole row and not just the individual cell. Any ideas? Please, See the following screenshot to see the resizing in action:

enter image description here

This is what I’d expect if I resize cell (0,0) (the image has being manually edited by me):

enter image description here

Thanks in advance!

  • 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:17:19+00:00Added an answer on June 12, 2026 at 4:17 am

    If you remove the line setting the row for your verticalGridSplitter and set them to span NumRows, you will see your vertical splitters. But ultimately, I think you are trying to do something that the grid with splitters can’t do. You can’t resize the width and height of individual cells, only whole rows and columns.

    After all, if you make C0-R0 taller, what do you expect the rest of that row to do?

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

Sidebar

Related Questions

I'm new to C# and WPF. I will need to write a program to
I need to write VoIP/SIP Soft Phone in C# using WPF interface with Audio
I need to write a WPF excel-like grid control. I'm new to WPF and
I need to write some listViewItem ( using WPF ) - that contain image,
I need to write an WPF(4.0) application which has a DB but no tables
I need to write a C++ code coverage program that takes in another C++
I need to write some input data files for a python program, and I
I need to write a program that prints 0.(03) for input 1 and 33.
I need to write to a text file using JavaScript. I have a machine
I need to write a MATLAB script/program to a client; and I need 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.