I am building a Windows 8 app which needs to download RSS data from the internet.
There is an awaited GetFeedsAsync() method which is responsible for this, being called in the (async) LoadState method of the HomePage of my app.
I have chose to delegate that task to a background thread:
await Task.Run(() => feedDataSource.GetFeedsAsync());
All I want is to show a ProgressRing and keep it active until the process finishes and downloaded data is ready to be displayed.
I defined the ProgressRing in XAML:
<ProgressRing x:Name="LoadingProgressRing" IsActive="True" Foreground="White" Margin="0,400,0,0" Width="80" Height="80" VerticalAlignment="Top" Canvas.ZIndex="1" />
And then added these 2 lines in the code-behind:
LoadingProgressRing.IsActive = true;
await Task.Run(() => feedDataSource.GetFeedsAsync());
LoadingProgressRing.IsActive = false;
When the app is launched, it navigates to the HomePage where the ProgressRing shows up for 1 second and then disappears. The data downloading finishes after 20 seconds and then shows up as it should.
Why is the ProgressRing acting like this? I cannot think of any reason for it to become inactive until the
LoadingProgressRing.IsActive = false;
command is executed.
Try adding Grid.Row="1" to your ProgressRing element i.e :-
<ProgressRing x:Name="LoadingProgressRing" IsActive="True" Foreground="White" Margin="0,400,0,0" Width="80" Height="80" VerticalAlignment="Top" Canvas.ZIndex="1" Grid.Row="1" />
Edit
To clarify a bit more - I was getting this exact problem of the progress bar appearing for a second and vanishing and it was nothing to do with awaiting, but was because I hadn't specified the grid row for the progress bar on my page.
My page had two row definitions:
<Grid.RowDefinitions> <RowDefinition Height="140"/> <RowDefinition Height="*"/> </Grid.RowDefinitions>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With