WPF animation stutters from time to time, while html in webview2 does not, I'm so confused #11607
Replies: 5 comments 1 reply
-
|
Similar question on stackoverflow: https://stackoverflow.com/q/3002271/14963554 |
Beta Was this translation helpful? Give feedback.
-
|
net8.0-windows.zip This sample app I built compared the WPF native animation with webview2 animation, the up is WPF animation, down is webview2 animation, you can clearly see the stuttering in WPF animation, while the webview2 one is super smooth. |
Beta Was this translation helpful? Give feedback.
-
|
@NkvXness I saw your reply from email github sends me, and really thank you for your reply, I have uploaded sample project above, which re-produced the issue: it compares between WPF animation and the webview2 one, you can checkout the code and experiment with it freely. |
Beta Was this translation helpful? Give feedback.
-
|
I ran the sample locally, and on my machine, the WebView2 version is clearly smoother than the native WPF version. I tried a few WPF-side changes. The best result I got was not with Storyboard, but by driving the WPF marquee manually from CompositionTarget.Rendering. That made the WPF version a lot smoother, although it still did not remove the stutter completely. One other thing that helped on my laptop was assigning the sample .exe to the high-performance GPU in Windows Graphics Settings. After that, the WPF version got much closer to the WebView2 version, but I could still catch occasional small stutters. A few other things I tried:
I also logged frame gaps from CompositionTarget.Rendering. At 144 Hz, the expected interval is about 6.94 ms, but I occasionally saw gaps such as 20.83 ms, 27.78 ms, and 34.72 ms. Most of those did not line up with managed GC activity, so GC does not look like the main cause in my test. At this point I’m leaning toward this being more of a WPF frame pacing / presentation timing issue, possibly affected by GPU selection, rather than a pure text rendering problem. For the pure WPF version, the best workaround I found so far is still: CompositionTarget.Rendering + assigning the process to the high-performance GPU in Windows Graphics Settings. That improves the WPF version a lot on my machine, but it still does not fully match the WebView2 version. This is only based on my machine, of course, but I hope it helps narrow the issue down a bit. |
Beta Was this translation helpful? Give feedback.
-
|
FWIW: I also played around with your code and tried a few "tricks". I removed the TranslateTransform within the animation and simply moved the TextBlock directly on the Cavas' X-axis. I tried using KeyFrames. I also went from using a Textblock to a custom UIElement where I drew the text via FormattedText in OnRender all by myself. Long story short: Unfortunately nothing seemed to make any difference on my machine regarding the stutter. I suspect this to be a problem buried somewhere deep in WPF's Storyboard-Animation logic. I wish I were able to contribute something more helpful. Best wishes from Germany. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, everyone, hello dear developers here.
I'm developing a marquee animation with WPF:
I come up with this simple xaml code that performs the marquee animation on a textblock back and forth:
However, I found the animation sometimes stutter, not looking smooth, it visually feels like some frames are being skipped from time to time.
Then I try to implement the same animation in html in webview2:
The html code in jsx(I'm using react.js):
App.scss:
The webview2 code is very simple, I just reference the react.js dev server as startup url:
And then I got very very smooth marquee animation in webview2.
I do hope WPF animation could be as smooth as the one in webview2, I have tried Bitmap Cache:
I also tried disabling
UseLayoutRounding:But all these methods did not work. Just I'd like to ask if anyone knows how to get rid of the stutter in WPF animation?
Also I'm confused, of course I can migrate my code to use webview2, but is it considered the best practice?
Beta Was this translation helpful? Give feedback.
All reactions