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 8570439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:33:29+00:00 2026-06-11T18:33:29+00:00

I’m writing a UI app that allows the user to paste a grid of

  • 0

I’m writing a UI app that allows the user to paste a grid of numbers into it that will be sent to a remote server. Client could be WPF or Silverlight.

I’ve tried a Grid of Textbox controls using DataObject.AddPastingHandler to hook the user pasting input, converting from tab-separated rows in a string to Textbox controls. This takes 12 seconds (!) to update itself after the user pastes in just 122×161 cells from Excel which is unacceptably slow. Dissecting the string takes 0.1s, adding the rows and columns takes 1s, constructing and inserting the TextBox controls takes 2s and the remainder of the 12s appears to be spent drawing the TextBox controls for the first time.

I’ve also tried DataGrid but it doesn’t seem to handle 2D arrays well, preferring a 1D array of objects that it dissects for properties using reflection.

Now I’m contemplating just using a Canvas and drawing the numbers myself, which seems insane. Is there a simple way to use built-in WPF or Silverlight controls to get this done without painful lag for the user?

EDIT

I’ve since identified TextBox as the culprit because it is insanely slow. Here’s some F# code that illustrates the problem (replace TextBox with TextBlock and its 40x faster, which is still orders of magnitude slower than it should be but is acceptable in this instance):

open System.Windows

let app = Application()

let readClipboard() =
  let data = (Clipboard.GetData "Text") :?> string
  [|for row in data.Split[|'\n'|] do
    match row.Split[|'\t'|] with
    | [||] | [|""|] -> ()
    | row -> yield row|]

[<System.STAThreadAttribute>]
do
  let grid = Controls.Grid()
  let row = Controls.RowDefinition()
  Controls.RowDefinition() |> grid.RowDefinitions.Add
  Controls.ColumnDefinition() |> grid.ColumnDefinitions.Add
  let add i j ctrl =
    Controls.Grid.SetRow(ctrl, i)
    Controls.Grid.SetColumn(ctrl, j)
    grid.Children.Add ctrl |> ignore
  let paste() =
    let timer = System.Diagnostics.Stopwatch.StartNew()
    let data = readClipboard()
    printfn "Read clipboard %fs" timer.Elapsed.TotalSeconds
    let rows = data.Length
    let cols = data |> Array.fold (fun n xs -> xs.Length |> max n) 0
    printfn "%dx%d" rows cols
    grid.RowDefinitions.Clear()
    grid.ColumnDefinitions.Clear()
    grid.Children.Clear()
    for row in 1..rows do
      Controls.RowDefinition(Height=GridLength 24.0) |> grid.RowDefinitions.Add
    for col in 1..cols do
      Controls.ColumnDefinition(Width=GridLength 64.0) |> grid.ColumnDefinitions.Add
    printfn "Add rows and columns complete %fs" timer.Elapsed.TotalSeconds
    for i in 0..rows-1 do
      for j in 0..data.[i].Length-1 do
        Controls.TextBox(Text=data.[i].[j]) |> add i j
    printfn "Insert complete %fs" timer.Elapsed.TotalSeconds
    Media.CompositionTarget.Rendering.Add(fun _ ->
      printfn "Next Rendering event at %fs" timer.Elapsed.TotalSeconds
      app.Shutdown())
  let scroll = Controls.ScrollViewer(Content=grid)
  scroll.HorizontalScrollBarVisibility <- Controls.ScrollBarVisibility.Visible
  let window = Window(Content=scroll)
  window.Focusable <- true
  window.Focus() |> ignore
  window.PreviewKeyDown.Add(fun e ->
    let ctrl = Input.ModifierKeys.Control
    if Input.Keyboard.Modifiers &&& ctrl = ctrl then
      if e.Key = Input.Key.V then
        paste())
  app.Run window |> 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-06-11T18:33:31+00:00Added an answer on June 11, 2026 at 6:33 pm

    Turns out the problem is the built-in WPF TextBox control which is extremely slow. So we must either avoid it or replace it.

    In this case, I just wanted text so I can avoid it by using TextBlock instead, which brings the time to paste the cells down from 12s to 0.25s which is (just about) acceptable.

    For anyone who wants editable cells, apparently you should use TextBlock everywhere and only convert the one cell being edited to a TextBox because it is so slow.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a

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.