DataGridColumnHeader custom style problem

Mar 11, 2009 at 6:48 PM
I have custom column header (below is not real life example) style defined in the resource section of my user control. My user control is placed inside a  tab item of the tab control.

            <Style x:Key="demoStyle1"
           TargetType="{x:Type dg:DataGridColumnHeader}">

                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="Template">
                        <ControlTemplate TargetType="{x:Type dg:DataGridColumnHeader}">
                            <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">




Than, style is aplied to the datagrid:
        <dg:DataGrid x:Name="WPF_DataGrid" FontSize="12pt"
                 Grid.Row="1" Grid.Column="0"  Margin="10,2,10,2"
                 ItemsSource="{Binding Path=.}"
                 ColumnHeaderStyle="{StaticResource demoStyle1}">

I noticed that, when custom style is applied to the column header, DataGridColumnHeader.OnApplyTemplate is called every time my user control is removed an than added back to the visual tree (when another tab item is selected and than again first one selected).

Problem is that content of the TextBox entered by the user disappears after moving (selecting) the next tab item.

Thanks in advance, Sanjin
Mar 27, 2009 at 6:50 PM
<style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:238; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page Section1 {size:612.0pt 792.0pt; margin:70.85pt 70.85pt 70.85pt 70.85pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style>

Problem solved... While I was creating the test app, I pulled out the latest version of the libraries (DataGrid and Composite WPF and Silverlight) and rebuild my application.

Now, the previous behavior disappeared or I was doing something wrong in the first run.