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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:51:52+00:00 2026-05-23T14:51:52+00:00

I have a DataGrid that is used in two different views. In each case,

  • 0

I have a DataGrid that is used in two different views. In each case, I would like to have the last column resize it’s width if the user resizes the host control/view.

How would you do that?

Cheers,
Berryl

…

CanUserResizeColumns=”True”
>

    <DataGrid.Columns>
        <DataGridTextColumn 
            Header="Number" Binding="{Binding BusinessId}" IsReadOnly="True" 
            CanUserSort="True" CanUserResize="False"
            Width="75"/>
        <DataGridTextColumn 
            Header="Description" Binding="{Binding Description}" IsReadOnly="True" 
            CanUserSort="True" SortDirection="Ascending" CanUserResize="True"
            MinWidth="260" Width="Auto"  />
    </DataGrid.Columns>

</DataGrid>

UPDATE (Working Code)

I just named the column in the xaml and put the following code into the code-behind. If anyone has got a better idea or a way to optimize this, please let me know!

public partial class Listing : UserControl
{
    private double _currentColumnWidth;

    public Listing()
    {
        InitializeComponent();

        Loaded += OnLoaded;
        SizeChanged += OnSizeChanged;
    }

    private void OnLoaded(object sender, RoutedEventArgs e)
    {
        _currentColumnWidth = colDescription.ActualWidth;
    }

    private void OnSizeChanged(object sender, SizeChangedEventArgs e)
    {
        // split if control is not loaded yet
        if (_currentColumnWidth == 0) return;

        // only interested in width, not height
        var widthChanged = e.WidthChanged;
        if (!widthChanged) return;

        var delta = e.NewSize.Width - e.PreviousSize.Width;
        var newWidth = _currentColumnWidth + delta;
        if (newWidth <= colDescription.MinWidth || newWidth >= colDescription.MaxWidth) return;

        _currentColumnWidth = newWidth;
        colDescription.Width = new DataGridLength(_currentColumnWidth);
    }
}
  • 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-23T14:51:52+00:00Added an answer on May 23, 2026 at 2:51 pm

    Easy, just replace the width property in your XAML

    <DataGridTextColumn 
                    Header="Description" Binding="{Binding Description}" 
                    IsReadOnly="True" 
                    CanUserSort="True" SortDirection="Ascending" CanUserResize="True"
                    MinWidth="260" Width="Auto"  />
    

    to …

    <DataGridTextColumn 
                    Header="Description" Binding="{Binding Description}" IsReadOnly="True" 
                    CanUserSort="True" SortDirection="Ascending" CanUserResize="True"
                    MinWidth="260" Width="*"  />
    

    You do not require any code behind to do any handling of the width as WPF caters for this in XAML.

    the “*” indicates an AutoSize value 🙂

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

Sidebar

Related Questions

I have a problem with a data-bound DataGrid control, in that despite each column
I used to have a class in 1.1 for the Datagrid that inherited from
Using .NET 1.1, I have a DataGrid that contains three columns for each row.
I have long tables generated by datagrid control that go beyond the page width.
I have a web form that binds a DataGrid to a, normally, different data
I have such task - to create control that union two controls (DataGrid from
I have a DataGrid that is setup like this: <DataGrid AutoGenerateColumns=True GridLinesVisibility=Horizontal IsReadOnly=True ItemsSource={Binding
I have a DataGrid and I want to populate a column that contains a
I have a DataGrid, with an ItemTemplate that has an image and label. In
ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound

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.