ryokan
ryokan

Reputation: 115

How to implement WPF ListBox circular loading dialog?

I've got a WPF C# application that parses and loads a 1Gig text file. The current loading time for this app to parse the text file is approx 27 seconds. Therefore I would like to make an overlay circular dialog that displays the procentage of loading in the middle of the ListBox. Upon complete load the circular dialog must disappear.

Is it possible to keep this as a single-thread app?

I've spent the last couple of days looking at the web in search of a possible solution. The way I see it if at all possible then it must be a UserControl, but I haven't been able to find any straightforward solution?

My ListBox AXML:

<ListBox x:Name="listBoxTrackers" HorizontalAlignment="Left" Height="448" Margin="30,46,0,0" VerticalAlignment="Top" Width="740" SelectionChanged="listBoxTrackers_SelectionChanged" MouseDoubleClick="listBoxTrackers_MouseDoubleClick">
        [put the dialog overlay here]
    </ListBox>

Upvotes: 1

Views: 263

Answers (1)

Arwin
Arwin

Reputation: 1023

Which version of .NET are you using? From 4.0, what you would normally do is create an async function that reads the text file, call that function getting back a task, show an animated control overlayed on the control that is waiting, and then await the task you got back, and hide the animation again when complete.

Nicer of course would be to show a progress control, and have your text file parser post progress state that you assign to the progress control so your user can see the progress of the parsing. And of course you can show results in the list control while loading as well.

There are many options, but they are all going to be some form of multi-threading, but you shouldn't be afraid of that - the wpf user interface is built with that in mind.

In other words, take a look at the answer here: WPF ProgressBar usage when using Async/Await

Upvotes: 1

Related Questions