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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:27:15+00:00 2026-06-12T08:27:15+00:00

I have a really disturbing issue with .NET 4.0 DataGrid. I have proportional template

  • 0

I have a really disturbing issue with .NET 4.0 DataGrid. I have proportional template columns containing TextBlock with textWrapping enabled.

Problem is, the height of the DataGrid is not correct at load time (it’s sized as if the textblock were all wrapped at their maximum.) and does not update their size when resizing. It appears to be a layout issue (MeasureOverride and ArrangeOverride seems to be called when proportional sizes are not resolved, and not called afterwards…) but I haven’t been able to solve it.

Here is a simplified code that shows the issue :

MainWindow.xaml

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="700" Width="525">
<StackPanel Width="500">
    <Button Content="Add DataGrid" Click="Button_Click" />
    <ItemsControl x:Name="itemsControl">
        <ItemsControl.ItemContainerStyle>
            <Style>
                <Setter Property="Control.Margin" Value="5" />
            </Style>
        </ItemsControl.ItemContainerStyle>
    </ItemsControl>
</StackPanel>

MainWindow.xaml.cs

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace WpfApplication1
{
public partial class MainWindow : System.Windows.Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        itemsControl.Items.Add(CreateDataGrid()); 
    }

    private DataGrid CreateDataGrid()
    {
        var dataGrid = new DataGrid() { HeadersVisibility = DataGridHeadersVisibility.Column };
        dataGrid.MaxWidth = 500;
        dataGrid.Background = Brushes.LightSteelBlue;
        dataGrid.Columns.Add(GetDataGridTemplateColumn("Label", "Auto"));
        dataGrid.Columns.Add(GetDataGridTemplateColumn("Value", "*"));
        dataGrid.Items.Add(new Entry() { Label = "Text Example 1", Value = "Some wrapped text" });
        dataGrid.Items.Add(new Entry() { Label = "Text Example 2", Value = "Some wrapped text" });
        return dataGrid;
    }

    private DataGridTemplateColumn GetDataGridTemplateColumn(string bindingPath, string columnWidth)
    {
        DataGridTemplateColumn result = new DataGridTemplateColumn() { Width = (DataGridLength)(converter.ConvertFrom(columnWidth))};
        FrameworkElementFactory cellTemplateframeworkElementFactory = new FrameworkElementFactory(typeof(TextBox));
        cellTemplateframeworkElementFactory.SetValue(TextBox.NameProperty, "cellContentControl");
        cellTemplateframeworkElementFactory.SetValue(TextBox.TextProperty, new Binding(bindingPath));
        cellTemplateframeworkElementFactory.SetValue(TextBox.TextWrappingProperty, TextWrapping.Wrap);
        result.CellTemplate = new DataTemplate() { VisualTree = cellTemplateframeworkElementFactory };
        return result;
    }

    private static DataGridLengthConverter converter = new DataGridLengthConverter();
}

public class Entry
{
    public string Label { get; set; }
    public string Value { get; set; }
}

}

enter image description here

enter image description here

  • 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-12T08:27:17+00:00Added an answer on June 12, 2026 at 8:27 am

    Finally found a solution : setting CanContentScroll to false on the DataGrid fixed the issue.

    <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really have problem with this one. So I have a jar with a
I have really weird problem with colors in interface builder. I set a color
ive got a really weird problem. i have no clue why its not working.
I have really big problem with calling JSON with jQueryUI autocomplete. I have this
I have really simple problem in my PHP script. There is a function defined
Hi I have really problem with merging two lists in such code like mergesort
I'm only really beginning IOS development but have a few years dev of ASP.net
I have really big Oracle table with many columns that are not relevant to
I have really simple XML (HTML) parsing ANTLR grammar: wiki: ggg+; ggg: tag |
I have really basic question. How can I get form id by input element

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.