Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Displaying a Matrix: ListView/GridView CellTemplates for rows and columns.

Displaying a Matrix: ListView/GridView CellTemplates for rows and columns.

Scheduled Pinned Locked Moved WPF
wpfcsharpwcfcomdesign
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bartosz Bien
    wrote on last edited by
    #1

    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 a CellTemplate for a column does not work (by design) when the DisplayMemberBinding is set. Do I need to write my own control from scratch, or is it possible to reach my goal using the ListView? 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's ItemsSource is assigned with an IEnumerator of MatrixRow objects.

    Best regards, BB http://bartoszbien.com

    S 1 Reply Last reply
    0
    • B Bartosz Bien

      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 a CellTemplate for a column does not work (by design) when the DisplayMemberBinding is set. Do I need to write my own control from scratch, or is it possible to reach my goal using the ListView? 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's ItemsSource is assigned with an IEnumerator of MatrixRow objects.

      Best regards, BB http://bartoszbien.com

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups