in XamlControlsGallery/ControlPages/ScrollViewer2Page.xaml.cs [243:319]
private void Scroller4_ZoomAnimationStarting(muxc.ScrollViewer sender, muxc.ZoomAnimationStartingEventArgs args)
{
try
{
ScalarKeyFrameAnimation stockKeyFrameAnimation = args.Animation as ScalarKeyFrameAnimation;
if (stockKeyFrameAnimation != null)
{
ScalarKeyFrameAnimation customKeyFrameAnimation = stockKeyFrameAnimation;
if (nameof(ZoomAnimationOptions.Default) != (string)cbZoomAnimation.SelectedItem)
{
float targetZoomFactor = (float)zoomFactorSlider.Value;
customKeyFrameAnimation = stockKeyFrameAnimation.Compositor.CreateScalarKeyFrameAnimation();
float deltaZoomFactor = (float)(targetZoomFactor - sender.ZoomFactor);
switch ((string)cbZoomAnimation.SelectedItem)
{
case nameof(ZoomAnimationOptions.Custom1):
// "Accordion" case
for (int step = 0; step < 3; step++)
{
customKeyFrameAnimation.InsertKeyFrame(
1.0f - (0.4f / (float)Math.Pow(2, step)),
targetZoomFactor + 0.1f * deltaZoomFactor);
deltaZoomFactor /= -2.0f;
}
customKeyFrameAnimation.InsertKeyFrame(1.0f, targetZoomFactor);
break;
case nameof(ZoomAnimationOptions.Custom2):
// "Teleportation" case
CubicBezierEasingFunction cubicBezierStart = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
new Vector2(1.0f, 0.0f),
new Vector2(1.0f, 0.0f));
StepEasingFunction stepEasingFunc = stockKeyFrameAnimation.Compositor.CreateStepEasingFunction(1);
CubicBezierEasingFunction cubicBezierEnd = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
new Vector2(0.0f, 1.0f),
new Vector2(0.0f, 1.0f));
customKeyFrameAnimation.InsertKeyFrame(
0.499999f,
targetZoomFactor - 0.75f * deltaZoomFactor,
cubicBezierStart);
customKeyFrameAnimation.InsertKeyFrame(
0.5f,
targetZoomFactor - 0.25f * deltaZoomFactor,
stepEasingFunc);
customKeyFrameAnimation.InsertKeyFrame(
1.0f,
targetZoomFactor,
cubicBezierEnd);
break;
default:
break;
}
customKeyFrameAnimation.Duration = stockKeyFrameAnimation.Duration;
args.Animation = customKeyFrameAnimation;
}
if (!string.IsNullOrWhiteSpace(tbZoomDuration.Text))
{
double durationOverride = Convert.ToDouble(tbZoomDuration.Text);
customKeyFrameAnimation.Duration = TimeSpan.FromMilliseconds(durationOverride);
}
}
}
catch (Exception ex)
{
}
}