We had some code successfully working with Xceed's WPF datagrid v.3.8. When we updated to their v.5.2 data grid, we lost one feature. All I want to do is get the grid column header captions to wrap to two lines. We set up a ContentTemplate on the column manager cells to do this, and it works on application startup. But, when you scroll the column headers off the screen and then back into view, the ContentTemplate formatting seems to be lost.
As I said, the same code works with the earlier version of the grid. Xceed will not help us with this problem because we are hosting the WPF grid on a Windows form (which was their suggestion in the first place).
The Xceed datagrid is on a .XAML UserControl. In the UserControl.Resources I define the DataTemplate like this:
<DataTemplate x:Key="columnManagerCellContentTemplate">
<TextBlock Text="{Binding}" TextWrapping="WrapWithOverflow" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DataTemplate>
I define a Style for the ColumnManagerCell to set up a ColumnManagerCell loaded event handler:
<Style TargetType="{x:Type xcdg:ColumnManagerCell}">
<EventSetter Event="Loaded" Handler="ColumnManagerCell_Loaded"/>
</Style>
And in the .XAML.cs file for the user control I have the ColumnManagerCell_Loaded event handler that assigns the ContentTemplate to the ColumnManagerCells:
internal void ColumnManagerCell_Loaded(object sender, RoutedEventArgs e)
{
ColumnManagerCell columnManagerCell = sender as ColumnManagerCell;
if (columnManagerCell != null)
{
if (columnManagerCell.ContentTemplate == null)
{
columnManagerCell.ContentTemplate = (DataTemplate)this.FindResource("columnManagerCellContentTemplate");
}
}
}
This is all code that was documented by Xceed a long time ago. As I said, it works to correctly wrap long column headers to 2 lines when I start the application. But, when I scroll the column headers out of view and then back into view, the formatting is gone.
I can also set the background color of the TextBlock in the DataTemplate, which works on startup, and then also disappears after scrolling the headers out of view.
Anyone have any suggestions on how I can get these settings to persist? I tried setting up an IsVisibleChanged event handler on the TextBlock and reset the TextWrapping property within that handler (I see that it is "None" at that point), but that didn't change the situation.
Any suggestions appreciated.
Thanks,
Mark