DataGrid in WPF apparently has a bug

T

tshad

In WPF, if I use the Datagrid as:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
WindowStartupLocation="CenterScreen"
FontFamily="Arial"
FontSize="14"
MinWidth="400"
SizeToContent="WidthAndHeight"
Loaded="Window_Loaded">
<Window.Resources>
<Style TargetType="WrapPanel">
<Setter Property="MaxWidth"
Value="500" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="104" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" MinHeight="40" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" MinHeight="78" />
</Grid.RowDefinitions>
<WrapPanel Grid.Row="2">
<Label>Primary Key:</Label>
<TextBox Name="txtPK"></TextBox>
</WrapPanel>
<WrapPanel Grid.Row="4">
<my:DataGrid Height="200" Name="grdData" Width="469"
IsReadOnly="True" ItemsSource="{Binding}" />
</WrapPanel>
</Grid>
</Window>

This works fine

If I add in a couple of datagrid columns:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
WindowStartupLocation="CenterScreen"
FontFamily="Arial"
FontSize="14"
MinWidth="400"
SizeToContent="WidthAndHeight"
Loaded="Window_Loaded">
<Window.Resources>
<Style TargetType="WrapPanel">
<Setter Property="MaxWidth"
Value="500" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="104" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" MinHeight="40" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" MinHeight="78" />
</Grid.RowDefinitions>
<WrapPanel Grid.Row="2">
<Label>Primary Key:</Label>
<TextBox Name="txtPK"></TextBox>
</WrapPanel>
<WrapPanel Grid.Row="4">
<my:DataGrid Height="200" Name="grdData" Width="469"
IsReadOnly="True" ItemsSource="{Binding}">

<my:DataGrid.Columns>
<my:DataGridTextColumn
Binding="{Binding Path=EmployeeID}"
Header="EmployeeID" />
<my:DataGridTextColumn
Binding="{Binding Path=OrderDate}"
Header="OrderDate" />\
</my:DataGrid.Columns>

< /my:DataGrid>
</WrapPanel>
</Grid>
</Window>

The program goes into some processing loop that shows as 80%+ activity in
TaskManager.

The only way to stop it is to stop it from Task Manager. It will ask you if
you want to save the files but pushing the OK button does you no good.

It starts up OK then but with the old files in it.

My c# code is:

private void CollectionSample()
{
ProductManager mgr = new ProductManager();
try
{
grdData.ItemsSource = mgr.BuildCollection();
}
catch (Exception exc)
{
}
}


Is this a known bug?

Thanks,

Tom
 
A

Alexander Mueller

tshad said:
In WPF, if I use the Datagrid as:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" ....

<my:DataGrid Height="200" Name="grdData" Width="469"
IsReadOnly="True" ItemsSource="{Binding}" />
</WrapPanel>

This works fine

If I add in a couple of datagrid columns:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
<my:DataGrid Height="200" Name="grdData" Width="469"
IsReadOnly="True" ItemsSource="{Binding}">
<my:DataGrid.Columns>
<my:DataGridTextColumn
Binding="{Binding Path=EmployeeID}"
Header="EmployeeID" />
<my:DataGridTextColumn
Binding="{Binding Path=OrderDate}"
Header="OrderDate" />\
</my:DataGrid.Columns>
< /my:DataGrid>
</WrapPanel>
</Grid>
</Window>

The program goes into some processing loop that shows as 80%+ activity in
TaskManager.

The only way to stop it is to stop it from Task Manager.

The DataGrid has some known bugs, that's for sure. Hope they'll get them
fixed with the "official" integration of the toolkit into silverlight.

Concerning your problem, did you try and set AutoGenerateColumns to
false, which you usually do when you define the columns by your own
markup?

MfG,
Alex
 
T

tshad

Alexander Mueller said:
The DataGrid has some known bugs, that's for sure. Hope they'll get them
fixed with the "official" integration of the toolkit into silverlight.

Concerning your problem, did you try and set AutoGenerateColumns to false,
which you usually do when you define the columns by your own
markup?

Actually, I did, but that was when I found this bug. It is similar to a bug
that was reported back in March.

I added my issue to the their bug report:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=420621


What I do is take the following code(which sort of works):

<my:DataGrid Height="200"
Name="grdData" Width="469" IsReadOnly="True"
ItemsSource="{Binding}" >

</my:DataGrid>

Then I add AutoGenerateColumns="False" and then add the DataGrid columns:

<my:DataGrid.Columns>
<my:DataGridTextColumn
Binding="{Binding Path=ProductId}" Header="Product ID" />
<my:DataGridTextColumn
Binding="{Binding Path=ProductName}" Header="Product Name" />
</my:DataGrid.Columns>

And end up with:

<my:DataGrid Height="200" AutoGenerateColumns="false"
Name="grdData" Width="469" IsReadOnly="True"
ItemsSource="{Binding}" >
<my:DataGrid.Columns>
<my:DataGridTextColumn
Binding="{Binding
Path=ProductId}" Header="Product ID" />
<my:DataGridTextColumn
Binding="{Binding
Path=ProductName}" Header="Product Name" />
</my:DataGrid.Columns>
</my:DataGrid>

I didn't have the AutoGenerateColumns tag in my response on their site, but
I just tried it and it still does it.

As soon as I paste in the DataGrid.Columns code - it locks it up.

Thanks,

Tom
 
A

Alexander Mueller

I didn't have the AutoGenerateColumns tag in my response on their site, but
I just tried it and it still does it.

As soon as I paste in the DataGrid.Columns code - it locks it up.

Well actualy looks like a bug.
Maybe not pasting the whole block but rather typing the code in
will help..

I remember having similar problems (VS got hung-up with high
CPU-consumption) sometimes when pasting bigger blocks of xaml, namely
ColumnDefinitons that referred to Templates of extern binary Resources
or as mentioned in the bug report you posted when pasting incomplete
XAML.
I managed to get around by editing the markup in an external editor,
cleaning the whole solution, manually build all projects you depend on
one-by-one. Then build the very project.

This worked most of the time when the designer seemed to have his days.
But i don't think it's actually a practice one should get used to.

Sigh! WPF still has its "teething troubles" (that what LEO translates me
for "Kinderkrankheit" .. ;-)

MfG,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top