I am trying to re-implement a form in WPF which was fairly easy to program in winforms and cannot see how to progress. The form consists of three panes. The right hand pane contains the detailed data - columns of flags which either contain the value Y or are blank, while the two left hand panes contain matrices which summarise the matches and discrepancies between the columns.
The number of columns (n) in the right hand pane is variable, and the two left-hand panes are n X n -so their size is dynamic too. When the user clicks a cell in one of the left hand panes, it is highlighted and used to highlight the appropriate columns in the right hand pane.
For example, consider the case of cell 1,2 of the Matches. Let us assume that it contains the value 2,and that the 1,2 cell of the Discrepancies contains 3. When the cell 1,2 is clicked, it is highlighted green,the corresponding cell on the differences panel is highlighted red, and the columns 1 and 2 are marked up with the matches, resulting in 2 corresponding entries highlighted green and 3 single entries highlighted red:
Column1 Column 2
green Y Y
red Y
green Y Y
red Y
red Y
I decided to use a listview to implement this in WPF. Since the arrays have variable sizes, I decided to set up the grid view programmatically. Here is part of the code (in VB.net):
Private Sub DefineColumns(ByRef _GridView As GridView, MaxIndex As Integer)
With _GridView
For i = 0 To MaxIndex
Dim _ColumnTitle = "P" & (i + 1)
Dim _TextBlock = New FrameworkElementFactory(GetType(TextBlock))
Dim _Binding = New Binding(_ColumnTitle)
_TextBlock.SetBinding(TextBlock.TextProperty, _Binding)
_TextBlock.SetValue(HorizontalAlignmentProperty, Windows.HorizontalAlignment.Right)
Dim _DataTemplate = New DataTemplate()
_DataTemplate.VisualTree = _TextBlock
Dim _Column = New GridViewColumn()
With _Column
.CellTemplate = _DataTemplate
.Header = (i + 1)
.Width = 39
End With
.Columns.Add(_Column)
Next
End With
End Sub
The WPF form works - but how can I achieve the highlighting I need? I really need to program it somehow and it does not seem to me that triggers are any use as I really want to mark things permanently so that I can scroll the right hand pane. All I need to do is mark the two selected cells in the left hand panes, and then loop down the selected columns on the right hand pane, marking matches in green and discrepancies in red. Can anyone help? It seems so simple in principle, but with WPF simple things can sometimes be very complicated to implement.