简体   繁体   中英

Binding smooth animation on ValueChanged event for a XAML ProgressBar

i searched a lot about this but can't find a solution for my exact case:

First, i'm doing a little download manager, i list all my downloads in a listview element. My Listview (named downloadListXaml ) have some GridViewColumn binded to a my element (stuff like file name, file size, and a progress bar). Every download is managed by a separate thread , every thread just update the progress value binded to my ProgressBar .

In my initial project every thread refreshed the UI on every change to Progress but this make the entire UI freeze sometime. So i maked a separate thread that refresh my Listview every 100ms and ONLY if some download thread are active, here the simple code used for refresh:

downloadListXaml.Items.Refresh();

This works and UI is always responsive, but the progress bar animation just jumps every 100ms to the next value, not good looking at all.

I want to smootly refresh it, and i found some solution, like this: How to update a progress bar so it increases smoothly?

The problem in that solution is that i need to refeer to my ProgressBar xaml element, but i just can access to my object binded to the ProgressBar .

So, i think my only solution is solve this XAML-Side , attaching an animation to the ValueChanged event of the ProgressBar .

I'm really new to XAML and i'm not even sure i can do this. Is this possible? How can i do it?

TL;DR version : i don't know how to animate a ProgressBar value change working only in XAML when ProgressBar value is binded to a code-side managed object.

i used the ProgressBarSmoother implementation from this answer: How to update a progress bar so it increases smoothly?

it works well, but in my case it tries to animate ProgressBar from 0 to correct value . So i had to add the " last drawn value " in my object binded to ListView and animate from that value to current progress value.

Maybe not the best solution but looks really smooth and UI is responsive! I like that :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM