I have C# + WPF application. I created animations that move element from one point to another. I have a hotkey that calls a method> The method start animation Animations on my PC works perfectly(I have very powerful PC) but if another user with decent PC use my application animations has some lags or freezes. It looks like it has low sample rate
So, the problem is animations works bad on other PC
I noticed that if I run my application and task manager I see that GPU load is consuming, when I run a method with animation begin GPU load is increasing and can be up to 15% everytime when I click on hotkey with a animation method.
Current Result: animation works bad, some lags
Expected Result: animation works fine and smoothly
How to make animation work good on all machines?
public class HotKeys
{
DoubleAnimation animShowCard = new DoubleAnimation(100, TimeSpan.FromMilliseconds(250));
DoubleAnimation animShowCardOffset = new DoubleAnimation(0, TimeSpan.FromMilliseconds(150));
public HotKeys(MainWindow _window)
{
SineEase sineEase = new SineEase();
sineEase.EasingMode = EasingMode.EaseOut;
animShowCard.EasingFunction = sineEase;
animShowCardOffset.EasingFunction = sineEase;
animShowCard.Completed += (s, e) =>
{
window.cardQuestionBorder.RenderTransform = new TranslateTransform(100, 0);
window.cardQuestionBorder.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animShowCardOffset);
};
}
//call a method with animation when D1 hotkey is clicked
if (e.Key == Key.D1)
{
e.Handled = true;
ShowCard();
}
//method that show animation
private void ShowCard()
{
window.cardQuestionBorder.RenderTransform = new TranslateTransform(-1600, 0);
window.cardQuestionBorder.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animShowCard);
}
}
I tried to change SampleRate of animation(60 frames is default value I think) to 25 or less but it go worse even on my PC:
Timeline.SetDesiredFrameRate(animShowCard, 25);
EDIT:
I recorded my application working on other PC, It consumes GPU load up to 45%
EDIT 2:
I found the root problem. It was shadow effect of a card. I used it in xaml. When I removed this thing animation has been working smooth and very good
<Border.Effect>
<DropShadowEffect Color="Black"
Direction="320"
BlurRadius="60"
ShadowDepth="40"
Opacity="0.8" />
</Border.Effect>
Is there any way to fix it? Can I use another shadow type? How can I use it in code behind?