Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7524301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:03:46+00:00 2026-05-30T03:03:46+00:00

I’m trying to write an automated test harness using WPF and F#. I’d like

  • 0

I’m trying to write an automated test harness using WPF and F#. I’d like to display aggregate test results as rows in a multi-column list. Ideally, I would like to present rich content in each cell, e.g. highlighting issues with specific tests using color or making details available via tooltips. However, I cannot figure out how to put anything richer than a plain string into a multi-column ListView.

Furthermore, I’m not a fan of XAML or data binding and prefer to write vanilla F# code. The simplest program I have been able to write that displays a multi-column WPF ListView is:

open System.Windows

let gridView = Controls.GridView()
let listView = Controls.ListView(View=gridView)

type SystemParams = { Name: string; Value: obj }

[<System.STAThread>]
do
  let column header binding =
    let binding = Data.Binding binding
    Controls.GridViewColumn(Header=header, DisplayMemberBinding=binding)

  for header, binding in ["Name", "Name"; "Value", "Value"] do
    column header binding
    |> gridView.Columns.Add

  for prop in typeof<SystemParameters>.GetProperties() do
    if prop.PropertyType <> typeof<ResourceKey> then
      { Name = prop.Name; Value = prop.GetValue(null, null) }
      |> listView.Items.Add
      |> ignore

  Application().Run(Window(Content=listView)) |> ignore

Although this works, I don’t like the way it requires the field names to be duplicated both in the type definition and as strings that are fed to WPF which presumably then uses reflection to resolve them at run-time (yuk!). Ideally, I would like to Add an obj array giving the WPF controls for each cell.

Is ListView capable of this? If so, how do you write a function that accepts a 2D array of controls and returns a ListView that visualizes them?

If not, I will probably use a Grid instead. I have tried DataGrid before and it is just a world of pain in comparison…

EDIT:

Thanks to the answers below, I have been able to come up with a solution. The multiColumnList function in the program below creates list of controls with the given headers and content with selectable rows:

open System.Windows

let multiColumnList columns contents onSelection =
  let gridView = Controls.GridView()
  let list = Controls.ListView(View=gridView)
  let column index header =
    let binding = Data.Binding(sprintf "[%d]" index)
    Controls.GridViewColumn(Header=header, DisplayMemberBinding=binding)
    |> gridView.Columns.Add
  Seq.iteri column columns
  list.ItemsSource <-
    [|for row in contents ->
        [|for elt in row ->
            box elt|]|]
  list.SelectionChanged.Add onSelection
  list

[<System.STAThread>]
do
  let columns = ["Name"; "Value"]
  let contents =
    [ for prop in typeof<SystemParameters>.GetProperties() do
        if prop.PropertyType <> typeof<ResourceKey> then
          yield [box prop.Name; prop.GetValue(null, null)] ]
  Application().Run(Window(Content=multiColumnList columns contents ignore))
  |> ignore
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:03:48+00:00Added an answer on May 30, 2026 at 3:03 am

    Your specific problem of duplicating the field names could be avoided by using an index based binding, instead of member name. See the changes to your example here:

    open System
    open System.Windows
    
    let gridView = Controls.GridView()
    let listView = Controls.ListView(View=gridView)
    
    [<System.STAThread>]
    do
      let column index header  =
        let binding = Data.Binding(sprintf "[%d]" index)
        Controls.GridViewColumn(Header=header, DisplayMemberBinding=binding)
    
      ["Name"; "Value"] 
      |> List.mapi column 
      |> List.iter gridView.Columns.Add
    
      for prop in typeof<SystemParameters>.GetProperties() do
        if prop.PropertyType <> typeof<ResourceKey> then
          ([| prop.Name; prop.GetValue(null, null) |] : Object array)
          |> listView.Items.Add
          |> ignore
    
      Application().Run(Window(Content=listView)) |> ignore
    

    Regarding giving the ListView a sequence of sequences of controls, that is somewhat lower level than ListView is intended to be used. ListView and DataGrid both assume that you have some roughly homogeneous collection of objects that you want show (generally as rows) and some idea of what information you want to show about those objects (the column definitions). Both controls will help in that situation, although I do agree that their general assumption that you want to use reflection over the members of a type can be annoying.

    If you want to be able to specify a grid of any controls, then as you mention the Grid panel layout is probably more suitable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.