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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:53:44+00:00 2026-05-24T16:53:44+00:00

I have a Grid that holds segments such as: — — ———– — ——————-

  • 0

I have a Grid that holds segments such as:

--
  ---
      -----------
                 ---
                    -------------------

Each segment’s visual length is dependant upon the total length, and its position depends upon the end of the previous segment.

I have a MultiBinding to achieve this, that calculates Width of 3 ColumnDefinition.

I first thought I’d calculate the entire ColumnDefinitions so that each item is placed correctly, but as it happens, the compiler doesn’t allow me to bind Grid.ColumnDefinitions, i.e you can’t do this:

<Grid.ColumnDefinitions>
     <MultiBinding Converter="{StaticResource yourConverter}">
            <Binding Path=firstValueForCalculus />
            <Binding Path=secondValueForCalculus />
            ...   
     </MultiBinding>
</Grid.ColumnDefinitions>

So now, I’m thinking my only option is to make 3 IMultiValueConverters, bind each of the 3 ColumnDefinition.Width to their respective converter, and calculate everything… but that sounds very nasty and my “Oh-My-God-You’re-Going-Down” alarm rang.

Any idea to do this elegantly?

Thanks!

EDIT: Yurek’s code a bit modified : (Is that what you meant? or did I destroy it? :p)

public class GridHelper
    {
        public static readonly DependencyProperty ColumnDefinitionsProperty =
            DependencyProperty.RegisterAttached("ColumnDefinitions", typeof(ColumnDefinitionCollection), typeof(GridHelper),
            new FrameworkPropertyMetadata(null, new PropertyChangedCallback(
            (sender, e) => 
            {
                var element = sender as Grid;
                if (element != null)
                {
                    element.ColumnDefinitions.Clear();
                    foreach (ColumnDefinition col in (IEnumerable<ColumnDefinition>)e.NewValue)
                    {
                        element.ColumnDefinitions.Add(col);
                    }
                    //element.ColumnDefinitions.AddRange((IEnumerable<ColumnDefinition>)e.NewValue);
                }
            })));


        public static IEnumerable<ColumnDefinition> GetColumnDefinitions(Grid element)
        {
            return (IEnumerable<ColumnDefinition>)element.GetValue(ColumnDefinitionsProperty);
        }

        public static void SetColumnDefinitions(Grid element, IEnumerable<ColumnDefinition> columnDefinitions)
        {
            element.SetValue(ColumnDefinitionsProperty, columnDefinitions);
        }
    }
  • 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-05-24T16:53:44+00:00Added an answer on May 24, 2026 at 4:53 pm

    You can’t set ColumnDefinitions using binding because it is read only. But there is an elegant solution – to use attched dependency property.

    public class GridHelper
        {
            public static readonly DependencyProperty ColumnDefinitionsProperty =
                DependencyProperty.RegisterAttached("ColumnDefinitions", typeof(ColumnDefinitionCollection), typeof(GridHelper),
                new FrameworkPropertyMetadata(null,
                (sender, e) =>
                {
                    var element = sender as Grid;
                    if(element != null)
                    {
                         element.ColumnDefinitions.Clear();
                         element.ColumnDefinitions.AddRange((IEnumerable<ColumnDefinition>)e.NewValue);
                    }
                }));
    
            public static IEnumerable<ColumnDefinition> GetColumnDefinitions(Grid element)
            {
                return (IEnumerable<ColumnDefinition>)element.GetValue(ColumnDefinitionsProperty);
            }
    
            public static void SetColumnDefinitions(Grid element, IEnumerable<ColumnDefinition> columnDefinitions)
            {
                element.SetValue(ColumnDefinitionsProperty, columnDefinitions);
            }
        }
    

    Now you can use binding for column definitions creation:

    <Grid>
         <local:GridHelper.ColumnDefinitions>
            <MultiBinding Converter="{StaticResource yourConverter}">
                <Binding Path=firstValueForCalculus />
                <Binding Path=secondValueForCalculus />
                ...   
            </MultiBinding>
         </local:GridHelper.ColumnDefinitions>
    </Grid>
    
    • 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 that has a checkbox item renderer in a cloumn
I have a Data Grid View inside a control that is displayed in a
Here's the scenario I have a Grid with some TextBlock controls, each in a
I am using MySql and PHP. I have a table groupXmembers that holds members
I have a grid that binds a number of child data objects to columns
I have a grid that is currently using Telerik Grids, I would like to
I have a grid that will edit small chunks of data based on a
I'm trying to have a grid that has items that have a custom layout/feel.
I have an windows forms application, with a form that holds 2 tabcontrols and
I have an editable grid that uses a store. I want to insert a

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.