Skip to main content

Microsoft Silverlight

Answered Question Templating the datagrid header?RSS Feed

(0)

chrisp_68
chrisp_68

Member

Member

18 points

38 Posts

Templating the datagrid header?

Any ideas how to dynamically template the datagrid header? I can template the columns cells like this

 DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();

templateColumn.Header = "My Header";

templateColumn.CellTemplate = (DataTemplate)Resources["myColumnTemplate"];

But cant seem to find a way to do a similar thing for the header. I need to be able to inject some extra controls into the header.

Thanks

Christian

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Templating the datagrid header?

Hello, the only way to achieve this is to create a HeaderStyle, and it must be done in XAML (at least the Style must be written in XAML).

First import the namespace System.Windows.Controls.Primitives:

xmlns:datap="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

Now write the HeaderStyle:

<data:DataGridTemplateColumn.HeaderStyle>

<Style TargetType="datap:DataGridColumnHeader">

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="datap:DataGridColumnHeader">

<Button Content="aaa"/>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

</data:DataGridTemplateColumn.HeaderStyle>

 

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.

Anand Tripathi
Anand Tr...

Member

Member

73 points

50 Posts

Re: Re: Templating the datagrid header?

Instead of Button (<Button Content="aaa"/>), I have a check box here. I need to chenge the checked property of it at run time. How can I refer that control and change it at run time?

http://www.anandtripathi.googlepages.com/
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities