2016-02-04 99 views
2

我想使我的進度工作的Windows手機8.1進度中的Windows Phone 8.1

這裏是我的代碼:

using (var writeStream = await newZipFile.OpenAsync(FileAccessMode.ReadWrite)) 
        { 
         using (var outputStream = writeStream.GetOutputStreamAt(0)) 
         { 
          using (var dataWriter = new DataWriter(outputStream)) 
          { 
           using (Stream input = webResponse.GetResponseStream()) 
           { 
            long totalSize = 0; 
            int read; 

            uint zeroUint = Convert.ToUInt32(0); 
            uint readUint; 

            while ((read = input.Read(buffer, 0, buffer.Length)) >0) 
            { 
             // totalSize += read; 
             totalSize = totalSize + read; 
             //pb2.Value = totalSize * 100/sizeFit; 
             await dispatcher.RunAsync(CoreDispatcherPriority.Normal,() => 
             { 
              //Declaration of variables 
              // load.progresschanged(totalSize * 100/sizeFit); 
              pb2.Value = totalSize * 100/sizeFit; 




             }); 

             readUint = Convert.ToUInt32(read); 
             IBuffer ibuffer = buffer.AsBuffer(); 
             dataWriter.WriteBuffer(ibuffer, zeroUint, readUint); 
            } 

            await dataWriter.StoreAsync(); 
            await outputStream.FlushAsync(); 
            dataWriter.DetachStream(); 
           } 
          } 
         } 
        } 

這裏的問題是,只有進度更新時的值爲100 任何幫助表示讚賞。

+0

使用'DispatcherTimer'來檢查並設置進度條中的值 –

回答

2

1)確保進度的MAXVALUE是在視圖100。
2)pb2.Value = sizeFit * 100/totalSize;可能是你正在計算百分比錯誤。由於我無法在代碼中找到sizeFit值,爲什麼不放置斷點並檢查返回的值是什麼