Data Grid Expanding To Infinite Width In Designer

Oct 28, 2008 at 9:58 PM
I was very excited to replace the CTP version of the Data Grid used by an application I'm developing with version one, but I've run into a maddening migration error.
When I try to view any data grid in the designer, the grid width starts expanding and hangs Visual Studio. The following XAML is fatal to the designer in the context of my project. (Although it's harmless if pasted into a fresh project).

Before I rip my project apart brick by brick, does anyone have any ideas?

<Window x:Class="InfiniteExpansion"
    Title="InfiniteExpansion" Height="300" Width="300">

Thanks in advance!
Oct 29, 2008 at 1:41 PM
I ran into the exact same thing. If I remove the column definitions (i.e. the entire <toolkit:DataGrid.Columns>) it doesn't happen anymore. For me it's not a huge problem since I add columns dynamically from code behind and I only had a few sample columns added in XAML to see how they look in the designer, but otherwise this (of course) is not a usable workaround.

I've made sure that I don't touch the columns from code behind in designer mode and AutoGenerateColumns is set to False, but still the same behaviour.
Oct 29, 2008 at 5:12 PM
Thanks for your reply. Doing the column configuration configuration in code would be pretty painful in our application's case (although if my back is against the wall I may have to do just that). I spent some time yesterday trying to isolate what particular reference might be involved, without success. I've tried a lot of variations around layout, for example does the problem occur without the enclosing grid, in a user control vs a window, etc. No luck there either. I've even tried nuking the project file and building a new one, with the same results. At this point I'm running out of ideas.
Oct 30, 2008 at 1:41 PM
Have you tried setting the DataGrid MaximumWidth property?
Oct 30, 2008 at 2:20 PM
I tried it out and could not repro.  Of course, I did start with a fresh project though.  What else do you need besides your code snippet above?
Oct 30, 2008 at 4:38 PM
After a bit more digging, I have a repro case. I can get it to break consistently on my machine, but others aren't affected.
 I've uploaded the zipped project file to, but here are the important bits:

A user control holding a grid like this:


                <ResourceDictionary Source="ApplicationResources.xaml"/>
    <toolkit:DataGrid IsReadOnly="True" Margin="3" x:Name="JobDataGrid">
            <toolkit:DataGridTextColumn Header="Column" Binding="{Binding Project.Program.Name}"></toolkit:DataGridTextColumn>

The referenced ApplicationResources file has only one style:

    <Style TargetType="{x:Type Button}">
        <Setter Property="Width" Value="80" />
        <Setter Property="Height" Value="24" />
        <Setter Property="Margin" Value="3" />

When viewing the grid in design mode (on an unaffected machine) Visual Studio inserts a little button to the left of the columns that, when clicked, generates a "SelectionChanged" handler for the grid. On my machine it looks like the process of figuring out how wide that button should be goes awry, probably because of the width attached to the default button style.
Nov 22, 2008 at 8:44 PM
Edited Nov 22, 2008 at 8:46 PM
After digging I found the same problem. But it was actually because of a style which had targeted Button class.
My problem was this style and after removing it the problem was solved :

< TargetType="Button">
Setter Property="Margin" Value="3"/>

I think that if you remove your referenced style section your problem would be solved too.
Thank you for mentioning it.
Jan 13, 2009 at 4:55 PM
try setting




for your datagrid and see if it works...

Feb 12, 2009 at 4:22 AM
Thanks Tufan,I was facing the same problem but once i applied your trick its solved..thanks