Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Error from RC0 DataGrid related changes
5 replies. Latest Post by sladapter on September 29, 2008.
(0)
sladapter
All-Star
17441 points
3,172 Posts
09-26-2008 11:53 AM |
Anybody knows how to set DataGridColumn.Header in RC0? My code used to work this way:
DataGridColumn col = new DataGridTextColumn();
...// code to set binding etc
HyperlinkButton b = new HyperlinkButton(); b.Content = "MyHeader" b.HorizontalAlignment = HorizontalAlignment.Center;
col.Header = b; // Cause of the error is this line
theGrid.Columns.Add(col); // Error in this line
Now I'm getting run-time error "Content does not support UIElements, use ContentTemplate instead". What dose this mean?
If I comment out col.Header = b line, it works.
I tried to set col.Header = new Grid(), got same error. How do we set the col.Header now?
I have read the breaking changes, but I did not find any DataGrid related changes.
CraigN
Member
352 points
89 Posts
09-27-2008 4:25 PM |
I remember seeing something like this in my testing as well, but I was working in XAML and not code-behind. I am not in front of my dev PC right now but if I recall correctly you need to put the content inside a DataTemplate.
09-27-2008 11:04 PM |
There is no Header.Template property that I can set. I need dynamically generate those columns and I don't want to use default header either. How are we going to do this?
Why can't we set a control to the Header anymore? What the Header property is for now? This just puzzles me.
Tregarick
13 points
24 Posts
09-28-2008 7:15 AM |
Had the same issue in XAML tried using DataTemplate and ContentTemplate nothing works it just locks my visual studio and maxes out my CPU. The DataGrid headers have been totally messed up, I think you can only apply text to the content property as I have seen others report that even binding on the Content property has broken. Think this is more of a Beta 3 release than an RC0 I use the header template loads an now all my grids are broken :-)
Yi-Lun L...
25052 points
2,747 Posts
09-29-2008 8:05 AM |
Hello, please refer to http://silverlight.net/forums/p/30592/99042.aspx#99042.
09-29-2008 10:21 AM |
Yi-Lun Luo,
Thanks for the information. I can now show custom DataGrid header.
But with custom header, column sort is off even I set the col.SortMemberPath. Why is that? It used to work in beta2.
[Edit]
OK, I found Sort can work if the custom header does not use Button or HyperlinkButton. But as long as I define Template in the Style, the image that indicating the current sort is no longer showing up.
I guess this makes some sense. If user define their own Header Template, they should be responsible for how they want their header really look like including the sort image.
[End Edit]
Column reorder is also off when using custom header. It used to error out in beta2.