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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:28:11+00:00 2026-06-10T10:28:11+00:00

I think I am missing something important but I just cannot figure it out.

  • 0

I think I am missing something important but I just cannot figure it out. I want to have multiple grids share the same column width, therefore I am using sharedsizegroups, but I just cannot seem to get it working.

xaml:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1"
        Title="MainWindow"
        Width="525"
        Height="350">
    <StackPanel x:Name="sg"
                local:exGrid.IsSharedSizeScope="True"
                Orientation="Vertical">
        <Button Click="Button_Click" Content="Click Me" />
    </StackPanel>
</Window>

code behind:

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            sg.Children.Add(new exGrid("short", "loooooooooooooooooooooooooong", "a"));
            sg.Children.Add(new exGrid("veeeeeeeeeeeeeeeeeeery loooooooooooooooooooooooooong", "short", "a"));
        }
    }
}

exGrid.cs

namespace WpfApplication1
{
    class exGrid : Grid
    {
        public exGrid(string a, string b, string g)
        {
            this.SetValue(exGrid.IsSharedSizeScopeProperty, true);

            for (int i = 1; i <= 2; i++)
            {
                this.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto, SharedSizeGroup = g });
            }

            this.SetValue(exGrid.ShowGridLinesProperty, true);

            TextBlock tx1 = new TextBlock();
            tx1.Text = a;

            TextBlock tx2 = new TextBlock();
            tx2.Text = b;

            tx1.SetValue(exGrid.ColumnProperty, 0);
            tx2.SetValue(exGrid.ColumnProperty, 1);

            this.Children.Add(tx1);
            this.Children.Add(tx2);
        }
    }
}
  • 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-10T10:28:13+00:00Added an answer on June 10, 2026 at 10:28 am

    See MSDN example : http://msdn.microsoft.com/fr-fr/library/system.windows.controls.grid.issharedsizescope.aspx

    You just need to set the IsSharedSizeScopeProperty on the container of the grids, not on each grid :

    namespace WpfApplication1
    {
        class exGrid : Grid
        {
            public exGrid(string a, string b, string g)
            {
                // this.SetValue(exGrid.IsSharedSizeScopeProperty, true);
    
                for (int i = 1; i <= 2; i++)
                {
                    this.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto, SharedSizeGroup = g });
                }
    
                this.SetValue(exGrid.ShowGridLinesProperty, true);
    
                TextBlock tx1 = new TextBlock();
                tx1.Text = a;
    
                TextBlock tx2 = new TextBlock();
                tx2.Text = b;
    
                tx1.SetValue(exGrid.ColumnProperty, 0);
                tx2.SetValue(exGrid.ColumnProperty, 1);
    
                this.Children.Add(tx1);
                this.Children.Add(tx2);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think i must be missing something simple here but I can't figure out
I think I'm just missing something simple here but here is what I am
Not exactly an error, but I think I am missing something important here.. class
I think I'm missing something really obvious here... must be... but for some reason
This is a homework question, but I think there's something missing from it. It
I've read everything there is on subprocess.Popen but I think I'm missing something. I
I thought I had it figured out but now I'm missing something. First I
I think I am missing something about correct behaviour of Monitor.Enter and Monitor.TryEnter .
I think I'm missing something very obvious and its making my brain hurt. class
I think I am missing something about the sphinx extension for doctest. The typical

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.