Diederik Krols

The XAML Brewer

Workaround: WPF DataGrid hangs Visual Studio.NET

Welcome to a WPF DataGrid crash course ... literally. It will show you how Cider can give you a hangover.  It took me 45 minutes, 10 process kills, and a full reboot to figure out what was going on in my application, so I gladly share my experience.

 Part one: the bug

Create a WPF Form with an empty DataGrid, like this:

<Window x:Class="U2UConsult.DockOfTheBay.DataGridWorkaround"




   Title="Bug Workaround" SizeToContent="WidthAndHeight">









Then, add a style that adds a Margin to the Button control, e.g. as a Resource for the Window:

 <!-- Kaboom-->


    <Style TargetType="{x:Type Button}">

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




Now is a good time to save your solution.

Add a column to the DataGrid:

<toolkit:DataGridTextColumn Header="Test" />


You will probably see something like this now, with an ever increasing counter:

Cider -the WPF Designer for Visual Studio.NET- entered an infinite loop.

Start Task Manager and inspect Visual Studio.NET's process, it's consuming close to 100% CPU:

Kill the process.

What you just experienced is a confirmed bug. The current version of the WPF DataGrid hangs Visual Studio.NET's Designer when buttons are decorated with a margin.

Part two: the Workaround

So now you know what may cause this behavior. Fortunately this shouldn't stop you from using a DataGrid, because the workaround is simple. All you need to do is embed a style in your DataGrid that resets the button margin to zero:


    <!-- Workaround for bug: No button margins allowed -->

    <Style TargetType="{x:Type Button}">

        <Setter Property="Margin" Value="0" />


    <!-- End of Workaround -->


        <toolkit:DataGridTextColumn Header="Test" />




This is just one of the many inconveniences with the current version of the toolkit. I strongly advise you to regularly check the issue tracker if you're planning to use its components in production.

Comments are closed