0

Possible Duplicate:
WPF: How can I avoid the flickering of the checked checkboxes in a ListBox or a ListView ?

Is there anyone who has been able to solve this question yet?

WPF: How can I avoid the flickering of the checked checkboxes in a ListBox or a ListView?

I've been looking for this for over a week now & still no solution.

it's very anoying that it flickers when adding or even refreshing items.

.Net version 4.0.

Community
  • 1
  • 1
Zarkos
  • 457
  • 10
  • 30
  • Can you provide some more details..? Like the version of .Net Framework,OS etc you are using.I tried it in My Windows 7 Machine using Visualstudio 2010,alteast i am not able to reproduce the flickering – biju May 23 '11 at 07:07
  • .net version 4.0 & win7, i'm adding items to the listview & when I use: listview.Items.Refresh() the checkboxes inside the listview flicker – Zarkos May 23 '11 at 09:55
  • WPF isn't generally susceptible to flicker. Are you sure they're not animating? WPF CheckBoxes fade their check marks in and out, even if it's set to checked when you first show it. So when you first show a checked CheckBox, its check-mark fades in over half a second or so. This might be the behavior you're seeing. – Joe White May 23 '11 at 19:05

2 Answers2

0

Sorry, I don't know XAML very well, but could you try something like this?

NOTE: I don't think you can use a BackgroundWorker object in XAML, but you could use it in another class and find a way to pass the data into it.

The main idea here is to shift your work over to another thread, and populate it there.

...although, I must say: If you are really adding all of your items in one line (like is shown from your modified example below), I doubt there would be any flicker at all caused by this. Your flicker could be coming from somewhere else. Are there any event handlers that are triggered when the data source changes?

void Button_Click(object sender, RoutedEventArgs e) {
  using (BackgroundWorker worker = new BackgroundWorker()) {
    var items = new int[10000];
    worker.DoWork += delegate {
      for (int i = 0; i < items.Length; i++)
        items[i] = i + 1;
    };
    worker.RunWorkerCompleted += delegate {
      listBox.ItemsSource = items;
    };
    worker.RunWorkerAsync();
  }
}
  • mmm you can use a backgroundworker in xaml, no worries. But it's not only with adding the Items, I don't mind the window flickering 1 time when adding the items. But it's mainly when I do a refresh of the Items cause that happens with every change to the items inside the listbox/listview – Zarkos May 25 '11 at 06:37
  • My guess is something else is happening when your `listBox` is populated, triggering something else to update. Place a single breakpoint at your `button_click` event and run your code. When that `button_click` event is fired and your Debugger breaks execution, go into each code segment in your project and add a break point, (time consuming, I know), then press F5 to continue. What is the first function to be hit afterwards? If this routine doesn't trigger a refresh, remove the breakpoint, and hit F5 again. Do this until you find the **real** problem. –  May 25 '11 at 14:21
-1

Did you try double buffering.

Sujay Ghosh
  • 2,828
  • 8
  • 30
  • 47
  • Doesn't apply. This answer is about WinForms. The question is about WPF. WPF is retained-mode, so effectively already has double-buffering. – Joe White May 23 '11 at 18:55
  • what Joe White says ;) already looked @ why double buffering isn't inside WPF :) – Zarkos May 25 '11 at 06:35