Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Ink
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports C1.Silverlight.FlexGrid

Namespace VerticalHeaders
	Public Class CustomCellFactory
		Inherits CellFactory
		Public Overrides Sub CreateColumnHeaderContent(ByVal grid As C1FlexGrid, ByVal bdr As Border, ByVal range As CellRange)
			' let base class start
			MyBase.CreateColumnHeaderContent(grid, bdr, range)

			' rotate the content of headers for numeric and Boolean columns
			Dim type = grid.Columns(range.Column).DataType
			If type Is GetType(Double) OrElse type Is GetType(Integer) OrElse type Is GetType(Boolean) Then
				' remove content from original cell
				Dim cellContent = TryCast(bdr.Child, FrameworkElement)
				bdr.Child = Nothing

				' create layout transform to rotate header by 90 degrees
				'var lt = new System.Windows.Controls.LayoutTransformer(); // << this works too
				Dim lt = New C1.Silverlight.C1LayoutTransformer()
				lt.LayoutTransform = New RotateTransform() With {.Angle = -90}

				' apply transform to content
				lt.Content = cellContent
				cellContent.VerticalAlignment = VerticalAlignment.Center

				' assign content back to cell
				bdr.Child = lt
			End If
		End Sub
	End Class
End Namespace
