Erix
Erix

Reputation: 69

How to add an EasingFunction to an UWP app by code

A solution given to me on another question was to write and add a custom easing function to my UWP code. The example provided was this piece of code:

public class StepEasingFunction : EasingFunctionBase
{
    public double NormalizedStep { get; set; }

    protected override Freezable CreateInstanceCore()
    {
        return new StepEasingFunction {NormalizedStep = NormalizedStep};
    }

    protected override double EaseInCore(double normalizedTime)
    {
        var stepIndex = Math.Round(normalizedTime / NormalizedStep);
        return NormalizedStep * stepIndex;
    }
}

I searched the web and try different ways to implement this code in my app but I'm not able to. I don't know if this code goes into my namespace or I need to create an external class.

If I put the code in my namespace I'm getting errors EaseInCore and CreateInstanceCore:

no suitable method found to override 

and on Freezable:

Freezable does not exist in the namesape

I have read Microsoft and other sites info on easing functions but none shows a complete example on how to implement this in UWP C# code.

Any help would be appreciated.

Upvotes: 1

Views: 201

Answers (1)

robertos
robertos

Reputation: 1796

The EasingFunctionBase that you posted is a WPF (System.Windows) class. Unfortunately that class is not extensible on UWP (see this forum post: https://social.msdn.microsoft.com/Forums/en-US/81e9d88b-70c7-4ba2-92bf-7c3890b91f81/uwpeasingfunctionbase-uwp-how-to).

In your case you will likely need to use a custom animation in code, or use keyframes to simulate a different curve. You can also look at the Visual Layer API which does allow you to create custom easing functions.

Upvotes: 1

Related Questions