ProgressBar
에 대한 애니메이션을 수행 할 때 문제가 발생했습니다.WinRT - 업데이트 진행률 막대
내 목적은, 는 내가 ProgressBar.Value
업데이 트가 CopyAsync
및 CreateFolderAsync
을 처리 할 때마다합니다.
내가의 TextBlock
잘 실행되고있는 프로세스를 수행 할 때마다 (CopyAsync
및 CreateFolderAsync
)를 업데이트 될 것입니다 내 XAML 파일의 4 개 구성 요소가 항상 프로세스가 완료 될 때마다 업데이트 할 수 있습니다. 문제는 ProgressBar
에 있으며 모든 프로세스가 끝날 때 UI가 업데이트됩니다.
나는 Dispatcher.RunAsync
을 사용 중이며 TextBlock
및 ProgressBar
에 대한 업데이트 프로세스가 있습니다.
아래 코드는 ProgressBar
을 업데이트하는 방법을 알려주십시오.
에서 MainPage.xaml
<TextBlock Text="Files:" FontSize="72" Margin="363,270,834,402"></TextBlock>
<TextBlock Text="Folders:" FontSize="72" Margin="273,411,834,270"></TextBlock>
<TextBlock x:Name="Files" FontSize="72" Margin="582,270,609,402"></TextBlock>
<TextBlock x:Name="Folders" FontSize="72" Margin="582,411,588,270"></TextBlock>
<ProgressBar x:Name="FolderBar" Height="25" Margin="10,532,-10,211"></ProgressBar>
<ProgressBar x:Name="FileBar" Height="25" Margin="10,565,-10,178"></ProgressBar>
MainPage.xaml.cs를
private async void CopyFolder(string path)
{
IStorageFolder destination = ApplicationData.Current.LocalFolder;
IStorageFolder root = Package.Current.InstalledLocation;
if (path.Equals(ROOT) && !await FolderExistAsync(ROOT))
await destination.CreateFolderAsync(ROOT);
destination = await destination.GetFolderAsync(path);
root = await root.GetFolderAsync(path);
IReadOnlyList<IStorageItem> items = await root.GetItemsAsync();
// For count the total files
if (path.Equals(ROOT))
TotalFiles(path);
foreach (IStorageItem item in items)
{
if (item.GetType() == typeof(StorageFile))
{
IStorageFile presFile = await StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appx:///" + path.Replace("\\", "/") + "/" + item.Name));
if (!await FileExistAsync(path, item.Name))
{
IStorageFile copyFile = await presFile.CopyAsync(destination);
countFiles++;
if (copyFile != null)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
() =>
{
// The update for TextBlock is fine
Files.Text = countFiles.ToString();
// But for the ProgressBar it will update in the end of process
FileBar.Value = countFiles/totalFiles * 100;
});
}
}
}
else
{
if (!await FolderExistAsync(path + "\\" + item.Name))
{
StorageFolder createFolder = await destination.CreateFolderAsync(item.Name);
countFolders++;
if (createFolder != null)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
() =>
{
// The update for TextBlock is fine
Folders.Text = countFolders.ToString();
// But for the ProgressBar it will update in the end of process
FolderBar.Value = countFolders/totalFolders * 100;
});
}
}
CopyFolder(path + "\\" + item.Name);
}
}
}
코드를 통해 속성을 직접 설정하여 구성 요소를 업데이트하면 안됩니다. mvvm-pattern (http://en.wikipedia.org/wiki/Model_View_ViewModel) 또는 mvvm-light (http://mvvmlight.codeplex.com/) –