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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:37:06+00:00 2026-06-02T14:37:06+00:00

The grid in WPF currently has a grid system like this: Cols + +

  • 0

The grid in WPF currently has a grid system like this:

    Cols
   +   +   +   +   +
   | 0 | 1 | 2 | 3 | 
+--+---|---|---|---|---
 0 |   |   |   |   |
+--+---|---|---|---|---  Rows
 1 |   |   |   |   |   
+--+---|---|---|---|---
 2 |   |   |   |   | 
+--+---|---|---|---|---

Is there a way to make it behave like this:

    Cols
   +   +   +   +   +
   | 0 | 1 | 2 | 3 | 
+--+---|---|---|---|---
 2 |   |   |   |   |
+--+---|---|---|---|---  Rows
 1 |   |   |   |   |   
+--+---|---|---|---|---
 0 |   |   |   |   | 
+--+---|---|---|---|---

Ideally I would like the RowSpan to extend an item upwards instead of downwards.

Example:

My datasource stores a cube on the map as 0,0 with the intent of it being displayed on the bottom left corner. However the grid in WPF will put that cube on the top left. The other problem is the datasource gives me a 2×2 with the position of the bottom left “anchor” position with a width and height. The width and height are bound to ColSpan and RowSpan. The RowSpan is an issue because it will be expanded down the grid and not up.

  • 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-02T14:37:11+00:00Added an answer on June 2, 2026 at 2:37 pm

    You should be able to do this without having to create a custom or user control by using attached properties.

    Here’s a class that I think should be able to do what you want. Instead of binding the values of Grid.Row and Grid.RowSpan to your row and height, bind GridEx.RowFromBottom and GridEx.RowSpanFromBottom to them. The property change handlers for these properties will compute the new value of Grid.Row based on the values of those properties and the number of rows in the grid.

    One potential problem is that this may not update correctly if you’re adding or subtracting rows from the grid at runtime.

    public static class GridEx
    {
        public static readonly DependencyProperty RowFromBottomProperty = DependencyProperty.RegisterAttached("RowFromBottom", typeof(int?), typeof(GridEx), new FrameworkPropertyMetadata(default(int?), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsParentArrange | FrameworkPropertyMetadataOptions.AffectsParentMeasure, OnRowFromBottomChanged));
        public static readonly DependencyProperty RowSpanFromBottomProperty = DependencyProperty.RegisterAttached("RowSpanFromBottom", typeof(int?), typeof(GridEx), new FrameworkPropertyMetadata(default(int?), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsParentArrange | FrameworkPropertyMetadataOptions.AffectsParentMeasure, OnRowSpanFromBottomChanged));
    
        private static void OnRowFromBottomChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var grid = GetContainingGrid(d);
            int? rowFromBottom = (int?) e.NewValue;
            int? rowSpanFromBottom = GetRowSpanFromBottom(d);
            if (rowFromBottom == null || rowSpanFromBottom == null) return;
            int rows = grid.RowDefinitions.Count;
            int row = Math.Max(0, Math.Min(rows, rows - rowFromBottom.Value - rowSpanFromBottom.Value));
            Grid.SetRow((UIElement) d, row);
        }
    
        private static void OnRowSpanFromBottomChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var grid = GetContainingGrid(d);
            int? rowFromBottom = GetRowFromBottom(d);
            int? rowSpanFromBottom = (int?)e.NewValue;
            if (rowFromBottom == null || rowSpanFromBottom == null) return;
            int rows = grid.RowDefinitions.Count;
            int row = Math.Max(0, Math.Min(rows, rows - rowFromBottom.Value - rowSpanFromBottom.Value));
            Grid.SetRow((UIElement)d, row);
            Grid.SetRowSpan((UIElement)d, rowSpanFromBottom.Value);
        }
    
        public static int? GetRowFromBottom(DependencyObject obj)
        {
            return (int?) obj.GetValue(RowFromBottomProperty);
        }
    
        public static void SetRowFromBottom(DependencyObject obj, int? value)
        {
            obj.SetValue(RowFromBottomProperty, value);
        }
    
        public static int? GetRowSpanFromBottom(DependencyObject obj)
        {
            return (int?)obj.GetValue(RowSpanFromBottomProperty);
        }
    
        public static void SetRowSpanFromBottom(DependencyObject obj, int? value)
        {
            obj.SetValue(RowSpanFromBottomProperty, value);
        }
    
        private static Grid GetContainingGrid(DependencyObject element)
        {
            Grid grid = null;
            while (grid == null && element != null)
            {
                element = LogicalTreeHelper.GetParent(element);
                grid = element as Grid;
            }
            return grid;
        }
    }
    

    If you have any questions about what’s going on here, feel free to ask.

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

Sidebar

Related Questions

I have a WPF Grid with a XAML similar to this: <Grid width=200 Height=200
I need to create a WPF grid dynamically from code behind. This is going
I wanted to make a function that populates a Grid in WPF with pictures.
I'm currently creating a MSPaint-like WPF-application and struggling with the implementation of a snappable
I currently try to create classes for a paint-like WPF application. I have to
i`m currently playing around with WPF and now i wonder what would be the
I need to write a WPF excel-like grid control. I'm new to WPF and
I am currently populating my WPF grid using a data collection that implements ITypedList
Im currently creating a custom control (based on the WPF DataGrid). What i would
I have a .Net 4.0 WPF application using a data grid. Currently after sorting

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.