Answered by:
Manage ProgressBar from a DownloadClass

Question
-
I have a ProgressBar in my MainPage.xaml:
<ProgressBar HorizontalAlignment="Center" Height="90" Margin="0,-30,0,0" VerticalAlignment="Center" Width="600" x:Name="BarProgress" />
And then in MainPage.xaml.cs there is the code for downloading data:
public async Task Download(string fileName, string fileId) private async Task HandleDownloadAsync(DownloadOperation download, bool start) private async Task DiscoverActiveDownloadsAsync() private void DownloadProgress(DownloadOperation download) { double percent = 100; if (download.Progress.TotalBytesToReceive > 0) { percent = download.Progress.BytesReceived * 100 / download.Progress.TotalBytesToReceive; } BarProgress.Value = percent; }
And it works great! I can see the ProgressBar proceeds until the download ends!
But if i want to create a new class such as DownloadData.cs and then put inside all the code for downloading data, how can i invoke the BarProgress.Value?!? I've done a lot of tentatives, such as MainPage.BarProgress.Value = percent, but i receive a lot of errors because BarProgress is inaccesible...
- Edited by JackieLeManchic Saturday, September 28, 2013 1:47 PM
Saturday, September 28, 2013 1:46 PM
Answers
-
Hi Jackie,
Take a look at this sample: http://code.msdn.microsoft.com/windowsapps/Basic-Controls-29318599.The second scenario is talking about ProgressBar, and the value is binding to a SliderBar.
Your code can be used to set the value for progressbar, check what is the maximum of your progressbar, if max is 100, but you set a percentage value to it, surely you will see nothing.
Best Regards,
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Jamles HezModerator Thursday, October 10, 2013 9:06 AM
Monday, September 30, 2013 8:10 AMModerator -
Hi Jackie,
A tutorial for you to know the data binding stuff: Quickstart: Data binding to controls.
More data binding samples can be found here: XAML data binding sample.
Best Regards,
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Jamles HezModerator Thursday, October 10, 2013 9:05 AM
Tuesday, October 1, 2013 1:32 AMModerator
All replies
-
Hi JackieLeManchic,
ProgressBar.Value is inaccessiable? The Value property of ProgressBar.Value should be both readable and writable. Maybe you could try to binding a value instead of set a value.
Best Regards,
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Monday, September 30, 2013 4:08 AMModerator -
Hi James, thank you for your answer...how can i access the ProgressBar from a generic class? MainPage.BarProgress.Value = percent, is it the right way?!
Could you provide a simple example for binding that value?!?
Thank you in advance!
Monday, September 30, 2013 7:46 AM -
Hi Jackie,
Take a look at this sample: http://code.msdn.microsoft.com/windowsapps/Basic-Controls-29318599.The second scenario is talking about ProgressBar, and the value is binding to a SliderBar.
Your code can be used to set the value for progressbar, check what is the maximum of your progressbar, if max is 100, but you set a percentage value to it, surely you will see nothing.
Best Regards,
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Jamles HezModerator Thursday, October 10, 2013 9:06 AM
Monday, September 30, 2013 8:10 AMModerator -
James, i've seen the example you suggested me and it's very interesting!
The value property of the ProgressBar is changed at RunTime through a Slider element. But if i try to Bind the value of the progress bar in my DownloadData.cs class i'm not able...Do you know some other example for binding data at runtime?
I already use Binding data but for static resource...here instead the value of the progress bar change at runtime and here starts the headache!!!
Monday, September 30, 2013 10:03 AM -
Hi Jackie,
A tutorial for you to know the data binding stuff: Quickstart: Data binding to controls.
More data binding samples can be found here: XAML data binding sample.
Best Regards,
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Jamles HezModerator Thursday, October 10, 2013 9:05 AM
Tuesday, October 1, 2013 1:32 AMModerator