Displaying a Matrix: ListView/GridView CellTemplates for rows and columns.
-
Hello, For my scientific application, I need a WPF control to display matrices of floating-point numbers. The sizes of matrices differ from 1*1 to approx. 100k*64. Rows may differ by foreground color (2 types), and columns may differ by background color (also 2 types). An example is here: http://bartoszbien.com/public/MatrixCtrl.png. Using a
ListView
, I've been able to display values in cells, and to color the text as needed. However, I'm not able to set background color for the columns, because setting aCellTemplate
for a column does not work (by design) when theDisplayMemberBinding
is set. Do I need to write my own control from scratch, or is it possible to reach my goal using theListView
? My style for the rows:<Style x:Key="MatrixRowStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Style.Triggers> <DataTrigger Binding="{Binding Type}" Value="Type1"> <Setter Property="Foreground" Value="Lime" /> </DataTrigger> <DataTrigger Binding="{Binding Type}" Value="Type2"> <Setter Property="Foreground" Value="RoyalBlue" /> </DataTrigger> </Style.Triggers> </Style>
My
DisplayMemberBinding
for the columns:column.DisplayMemberBinding = new Binding(string.Format("Values[{0}]", count));
The Values member comes from:
public class MatrixRow
{
public EType Type { get; set; }
public double[] Values { get; set; }
}The
ListView
'sItemsSource
is assigned with anIEnumerator
ofMatrixRow
objects.Best regards, BB http://bartoszbien.com
-
Hello, For my scientific application, I need a WPF control to display matrices of floating-point numbers. The sizes of matrices differ from 1*1 to approx. 100k*64. Rows may differ by foreground color (2 types), and columns may differ by background color (also 2 types). An example is here: http://bartoszbien.com/public/MatrixCtrl.png. Using a
ListView
, I've been able to display values in cells, and to color the text as needed. However, I'm not able to set background color for the columns, because setting aCellTemplate
for a column does not work (by design) when theDisplayMemberBinding
is set. Do I need to write my own control from scratch, or is it possible to reach my goal using theListView
? My style for the rows:<Style x:Key="MatrixRowStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Style.Triggers> <DataTrigger Binding="{Binding Type}" Value="Type1"> <Setter Property="Foreground" Value="Lime" /> </DataTrigger> <DataTrigger Binding="{Binding Type}" Value="Type2"> <Setter Property="Foreground" Value="RoyalBlue" /> </DataTrigger> </Style.Triggers> </Style>
My
DisplayMemberBinding
for the columns:column.DisplayMemberBinding = new Binding(string.Format("Values[{0}]", count));
The Values member comes from:
public class MatrixRow
{
public EType Type { get; set; }
public double[] Values { get; set; }
}The
ListView
'sItemsSource
is assigned with anIEnumerator
ofMatrixRow
objects.Best regards, BB http://bartoszbien.com
How about writing a custom
GridViewColumn.CellTemplate
?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.