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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:49:30+00:00 2026-06-17T16:49:30+00:00

I have a Grid having two columns. One column is twice the width as

  • 0

I have a Grid having two columns. One column is twice the width as other.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*" />
        <ColumnDefinition Width="2*" />
    </Grid.ColumnDefinitions>      
    <TextBox Grid.Column="0" Text="12"/>
    <TextBox Grid.Column="1" Text="" />
</Grid>

But during runtime when i type in second text box the width changes without maintaining the 1:2 ratio.
I dont want to keep fixed width. The width will be changed at runtime based on user entry.
I want the width to be in 1:2 ratio even if the width changes at runtime?

  • 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-17T16:49:31+00:00Added an answer on June 17, 2026 at 4:49 pm

    Here is another, alternative answer that you can modify into your needs.

    In this example, you can enter the width of your grid in the textbox in the first column. Or you can expand or decrease the width with the button. Just for illustration. You may have to change this for your purpose.

    MainWindow.cs

    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public static readonly DependencyProperty GridWidthProperty = DependencyProperty.Register("GridWidth", typeof(Double), typeof(MainWindow), new UIPropertyMetadata(300d, OnGridWidthPropertyChanged));
        public Double GridWidth
        {
            get { return (Double)GetValue(GridWidthProperty); }
            set
            {
                SetValue(GridWidthProperty, value);
                NotifyPropertyChanged("GridWidth");
            }
        }
    
        public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.Register("ColumnWidth", typeof(String), typeof(MainWindow), new UIPropertyMetadata("100", OnColumnWidthPropertyChanged));
        public String ColumnWidth
        {
            get { return (String)GetValue(ColumnWidthProperty); }
            set
            {
                SetValue(ColumnWidthProperty, value);
                NotifyPropertyChanged("ColumnWidth");
            }
        }
    
        private static void OnGridWidthPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            MainWindow ctl = sender as MainWindow;
    
            ctl.doGridWidthChanged();
            ctl = null;
        }
    
        private static void OnColumnWidthPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            MainWindow ctl = sender as MainWindow;
    
            ctl.doColumnWidthChanged();
            ctl = null;
        }
    
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
        }
    
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (sender == button1)
                this.GridWidth += 50;
            else if (sender == button2)
                this.GridWidth -= 50;
        }
    
        private void doGridWidthChanged()
        {
            if (Double.IsNaN(this.GridWidth))
                return;
    
            this.ColumnWidth = Math.Round((this.GridWidth / 3), 2).ToString();
        }
    
        private void doColumnWidthChanged()
        {
            Double columnwidthval = Double.NaN;
    
            if (!String.IsNullOrEmpty(this.ColumnWidth) && Double.TryParse(this.ColumnWidth, out columnwidthval))
                this.GridWidth = columnwidthval * 3;
            else
                this.ColumnWidth = Math.Round((this.GridWidth / 3), 2).ToString();
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(String PropertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
        }
    }
    

    And here is my XAML code.

    MainWindow.xaml

    <Window x:Class="WpfApplication3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WpfApplication3"
            Title="MainWindow" Height="600" Width="800">
        <Grid>
            <Grid Margin="0,60,0,0"
                  Width="{Binding Path=GridWidth}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*" />
                    <ColumnDefinition Width="2*" />
                </Grid.ColumnDefinitions>
                <Border Grid.Column="0" Background="GhostWhite" />
                <Border Grid.Column="1" Background="AliceBlue" />
                <Border Grid.ColumnSpan="2" BorderBrush="DimGray" BorderThickness="1" />
                <StackPanel Grid.Column="0" Orientation="Vertical" Margin="3">
                    <TextBlock Text="Single" />
                    <TextBox Text="{Binding Path=ColumnWidth, Mode=TwoWay}" />
                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Vertical" Margin="3">
                    <TextBlock Text="Double" />
                </StackPanel>
            </Grid>
            <Button Content="Increase" Height="34" HorizontalAlignment="Left" Margin="19,12,0,0" Name="button1" VerticalAlignment="Top" Width="90" Click="button_Click" />
            <Button Content="Decrease" Height="34" HorizontalAlignment="Left" Margin="120,12,0,0" Name="button2" VerticalAlignment="Top" Width="90" Click="button_Click" />
        </Grid>
    </Window>
    

    Hope that helps!

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

Sidebar

Related Questions

i have a data grid which is having two renderers. one is text box
I'm having a small problem. I have this grid with a column: <data:DataGrid ColumnHeaderStyle={StaticResource
I have a Devexpress DxGrid with two Columns with ComboboxEdit CellTemplate <dxg:GridControl Name=grid> <dxg:GridControl.Columns>
I'm trying to build a two-column layout where the width of the columns can
I am having some trouble creating a seamless photo grid. I have searched the
I have grid something like this: Ext.define('Exp.view.dashboard.Tv', { extend: 'Ext.grid.Panel', initComponent: function() { this.columns
I have a grid where first 2 columns are bound with ForeignKey (Category and
I gave it a try but it did not worked. I am having two
I have a two dimensional grid of cells. In this simulation, cells may request
I have two controls in this example but in the real application i have

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.