views:

14

answers:

1

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?

A: 

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