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

Namespace GridTooltips
    Partial Public Class MainPage
        Inherits UserControl
        Public Sub New()
            InitializeComponent()

            _grid.CellFactory = New ToolTipCellFactory()
            Dim list_Renamed = New List(Of Customer)()
            For i As Integer = 0 To 49
                list_Renamed.Add(New Customer() With {.Name = "Customer " & i.ToString(), .Age = 10 + i, .Active = i Mod 3 <> 0})
            Next i
            _grid.ItemsSource = list_Renamed

            For Each col As Column In _grid.Columns
                col.Tag = String.Format("tag for column '{0}'", col.ColumnName)
            Next col

            ' hook up event handler
            AddHandler _grid.PrepareCellForEdit, AddressOf _grid_PrepareCellForEdit
        End Sub

        ' customize editor by changing the appearance of the selection
        Private Sub _grid_PrepareCellForEdit(ByVal sender As Object, ByVal e As CellEditEventArgs)
            Dim b = TryCast(e.Editor, Border)
            Dim tb = TryCast(b.Child, TextBox)
            If tb IsNot Nothing Then
                tb.SelectionBackground = New SolidColorBrush(Colors.Blue)
                tb.SelectionForeground = New SolidColorBrush(Colors.Yellow)
            End If
        End Sub
    End Class

    ''' <summary>
    ''' CellFactory class that adds tooltips to cells.
    ''' </summary>
    Public Class ToolTipCellFactory
        Inherits CellFactory

        Public Overrides Sub CreateCellContent(grid As C1.Silverlight.FlexGrid.C1FlexGrid, bdr As System.Windows.Controls.Border, rng As C1.Silverlight.FlexGrid.CellRange)

            ' allow base class to create the cell
            MyBase.CreateCellContent(grid, bdr, rng)

            ' set cell tooltip
            Dim tip = String.Format("row: {0} col: {1}" & vbCrLf & "content: {2}" & vbCrLf & "column Tag: {3}", rng.Row, rng.Column, grid(rng.Row, rng.Column), grid.Columns(rng.Column).Tag)
            ToolTipService.SetToolTip(bdr, tip)

        End Sub
    End Class

    ''' <summary>
    ''' Simple data class.
    ''' </summary>
    Public Class Customer
        Private privateName As String
        <Display(Name:="Name")>
        Public Property Name() As String
            Get
                Return privateName
            End Get
            Set(ByVal value As String)
                privateName = value
            End Set
        End Property
        Private privateAge As Integer
        <Display(Name:="Age")>
        Public Property Age() As Integer
            Get
                Return privateAge
            End Get
            Set(ByVal value As Integer)
                privateAge = value
            End Set
        End Property
        Private privateActive As Boolean
        <Display(Name:="Active")>
        Public Property Active() As Boolean
            Get
                Return privateActive
            End Get
            Set(ByVal value As Boolean)
                privateActive = value
            End Set
        End Property
    End Class
End Namespace
