Skip to main content

Microsoft Silverlight

Answered Question Error from RC0 DataGrid related changesRSS Feed

(0)

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Error from RC0 DataGrid related changes

 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.

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

CraigN
CraigN

Member

Member

352 points

89 Posts

Re: Error from RC0 DataGrid related changes

 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.

Microsoft Xbox MVP

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Re: Error from RC0 DataGrid related changes

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.

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

Tregarick
Tregarick

Member

Member

13 points

24 Posts

Re: Error from RC0 DataGrid related changes

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 Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Error from RC0 DataGrid related changes

Hello, please refer to http://silverlight.net/forums/p/30592/99042.aspx#99042.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

sladapter
sladapter

All-Star

All-Star

17441 points

3,172 Posts

Re: Error from RC0 DataGrid related changes

 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.

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities