0

I have a Silverlight DataGrid with two columns. The headers of these two columns header have to be shown with a text box and column header title or name so that the text box can be used for filtering later.

So, I have used the following code to display the text box using a style:

<Style x:Name="mytemplate"
       x:Key="mytemplate"
       xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
       TargetType="dataprimitives:DataGridColumnHeader">
   <Setter Property="ContentTemplate" >
       <Setter.Value>
           <DataTemplate x:Name="ColHeaderTemplategrid">                      
               <StackPanel>                             
                   <TextBox x:Name="txtfilterBox"  KeyDown="txtfilterBox_KeyDown" Width="40"/>
               </StackPanel>
           </DataTemplate>
       </Setter.Value>
   </Setter>
</Style>

and I have applied the style to the column headers as below:

 ((DataGridTextColumn)column[0]).HeaderStyle = mytemplate;
 ((DataGridTextColumn)column[1]).HeaderStyle = mytemplate;

The thing is, now the text box is visible but the column header title or name disappears?

How do I show my column header along with the text box?

Jeff Yates
  • 61,417
  • 20
  • 137
  • 189
subash
  • 4,050
  • 14
  • 51
  • 78
  • Are you using some kind of binding for the column headers ? – Gabe Oct 27 '10 at 14:02
  • no i am not using any binding it automatically binds the heading previously but after applying this style to the columnheader i was not able to see the column header name – subash Oct 27 '10 at 14:05
  • Well that would be because your template only has a `textbox`, there is nothing in the template that would display the header like a `textblock` or something similar. – Gabe Oct 27 '10 at 14:08
  • IF you give me more code, like how you are setting the data to the columns I could try and give you more help. – Gabe Oct 27 '10 at 14:12
  • yeah that is right ,better we could insert a text block inside the datatemplate along with the text box ,but how to bind the text as the column header dynamically in the run time, – subash Oct 28 '10 at 05:00

1 Answers1

1

As u said i just inserted textblock in to the stackpanel of the template and solves the problem

the code is below

<Style x:Name="mytemplate" x:Key="mytemplate"  xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
                            TargetType="dataprimitives:DataGridColumnHeader">
            <Setter Property="ContentTemplate" >
                <Setter.Value>
                    <DataTemplate x:Name="ColHeaderTemplategrid">
                         <StackPanel>
                             <TextBlock Text="{Binding}" ></TextBlock>
                             <TextBox x:Name="txtfilterBox"  KeyDown="txtfilterBox_KeyDown" Width="40"/>
                        </StackPanel>

                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
subash
  • 4,050
  • 14
  • 51
  • 78