本文整理汇总了C#中Compositor.CreateScalarKeyFrameAnimation方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateScalarKeyFrameAnimation方法的具体用法?C# Compositor.CreateScalarKeyFrameAnimation怎么用?C# Compositor.CreateScalarKeyFrameAnimation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compositor
的用法示例。
在下文中一共展示了Compositor.CreateScalarKeyFrameAnimation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public static void Initialize(Compositor compositor)
{
// Create keyframes to select and unselect:
// - Since both Saturation and Opacity use float [0.0 -> 1.0], we can actually use the
// same keyframe instances and just bind to different properties.
NormalOnAnimation = compositor.CreateScalarKeyFrameAnimation();
NormalOnAnimation.InsertKeyFrame(1.0f, 1.0f /* opaque */);
NormalOnAnimation.Duration = NormalTime;
SlowOffAnimation = compositor.CreateScalarKeyFrameAnimation();
SlowOffAnimation.InsertKeyFrame(1.0f, 0.0f /* transparent */);
SlowOffAnimation.Duration = SlowTime;
}
示例2: CreateOpacityAnimation
public static KeyFrameAnimation CreateOpacityAnimation(Compositor compositor, TimeSpan duration)
{
ScalarKeyFrameAnimation kf = compositor.CreateScalarKeyFrameAnimation();
kf.InsertExpressionKeyFrame(1.0f, "this.FinalValue");
kf.Duration = duration;
kf.Target = "Opacity";
return kf;
}
示例3: CompositionImage
public CompositionImage()
{
this.DefaultStyleKey = typeof(CompositionImage);
this.Background = new SolidColorBrush(Colors.Transparent);
this._stretchMode = CompositionStretch.Uniform;
this.Loading += CompImage_Loading;
this.Unloaded += CompImage_Unloaded;
this.SizeChanged += CompImage_SizeChanged;
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
// Intialize the statics as needed
if (!_staticsInitialized)
{
_defaultPlaceholderBrush = _compositor.CreateColorBrush(Colors.DarkGray);
TimeSpan duration = TimeSpan.FromMilliseconds(1000);
_fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation();
_fadeOutAnimation.InsertKeyFrame(0, 1);
_fadeOutAnimation.InsertKeyFrame(1, 0);
_fadeOutAnimation.Duration = duration;
_scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
_scaleAnimation.InsertKeyFrame(0, new Vector2(1.25f, 1.25f));
_scaleAnimation.InsertKeyFrame(1, new Vector2(1, 1));
_scaleAnimation.Duration = duration;
_staticsInitialized = true;
}
// Initialize the surface loader if needed
if (!SurfaceLoader.IsInitialized)
{
SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);
}
_placeholderDelay = TimeSpan.FromMilliseconds(50);
_surfaceBrush = _compositor.CreateSurfaceBrush(null);
}
示例4: MainPage
public MainPage()
{
this.InitializeComponent();
ContactsCVS.Source = _list;
this.Loaded += (s, e) =>
{
_scrollViewer = ListView.GetScrollViewer();
_scrollViewer.DirectManipulationStarted += OnDirectManipulationStarted;
_scrollViewer.DirectManipulationCompleted += OnDirectManipulationCompleted;
// Retrieve the ScrollViewer manipulation and the Compositor.
_scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer);
_compositor = _scrollerViewerManipulation.Compositor;
// At the moment there are three things happening when pulling down the list -
// 1. The Refresh Icon fades in.
// 2. The Refresh Icon rotates (400°).
// 3. The Refresh Icon gets pulled down a bit (REFRESH_ICON_MAX_OFFSET_Y)
// QUESTION 5
// Can we also have Geometric Path animation so we can also draw the Refresh Icon along the way?
//
// Create a rotation expression animation based on the overpan distance of the ScrollViewer.
_rotationAnimation = _compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) * Multiplier, MaxDegree)");
_rotationAnimation.SetScalarParameter("Multiplier", 10.0f);
_rotationAnimation.SetScalarParameter("MaxDegree", 400.0f);
_rotationAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation);
// Create an opacity expression animation based on the overpan distance of the ScrollViewer.
_opacityAnimation = _compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)");
_opacityAnimation.SetScalarParameter("Divider", 30.0f);
_opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation);
// Create an offset expression animation based on the overpan distance of the ScrollViewer.
_offsetAnimation = _compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)) * MaxOffsetY");
_offsetAnimation.SetScalarParameter("Divider", 30.0f);
_offsetAnimation.SetScalarParameter("MaxOffsetY", REFRESH_ICON_MAX_OFFSET_Y);
_offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation);
// Create a keyframe animation to reset properties like Offset.Y, Opacity, etc.
_resetAnimation = _compositor.CreateScalarKeyFrameAnimation();
_resetAnimation.InsertKeyFrame(1.0f, 0.0f);
// Create a loading keyframe animation (in this case, a rotation animation).
_loadingAnimation = _compositor.CreateScalarKeyFrameAnimation();
_loadingAnimation.InsertKeyFrame(1.0f, 360);
_loadingAnimation.Duration = TimeSpan.FromMilliseconds(1200);
_loadingAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
// Get the RefreshIcon's Visual.
_refreshIconVisual = ElementCompositionPreview.GetElementVisual(RefreshIcon);
// Set the center point for the rotation animation.
_refreshIconVisual.CenterPoint = new Vector3(Convert.ToSingle(RefreshIcon.ActualWidth / 2), Convert.ToSingle(RefreshIcon.ActualHeight / 2), 0);
// Get the ListView's inner Border's Visual.
var border = (Border)VisualTreeHelper.GetChild(ListView, 0);
_borderVisual = ElementCompositionPreview.GetElementVisual(border);
PrepareExpressionAnimationsOnScroll();
};
this.Unloaded += (s, e) =>
{
_scrollViewer.DirectManipulationStarted -= OnDirectManipulationStarted;
_scrollViewer.DirectManipulationCompleted -= OnDirectManipulationCompleted;
};
}
示例5: InitComposition
/// <summary>
/// Initializes the Composition elements
/// </summary>
private void InitComposition()
{
// Compositor
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
// CompositionGenerator
_generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
// Fade Out Animation
_fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation();
_fadeOutAnimation.InsertKeyFrame(1f, 0);
_fadeOutAnimation.Duration = TransitionDuration;
// Fade In Animation
_fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation();
_fadeInAnimation.InsertKeyFrame(1f, 1);
_fadeInAnimation.Duration = TransitionDuration;
// Color Animation
_colorAnimation = _compositor.CreateColorKeyFrameAnimation();
_colorAnimation.Duration = TransitionDuration;
// Offset Animation
_offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();
_offsetAnimation.Target = "Offset";
_offsetAnimation.Duration = TransitionDuration;
_offsetAnimation.InsertKeyFrame(1f, Vector3.Zero);
// Alignment animations
_alignXAnimation = _compositor.CreateScalarKeyFrameAnimation();
_alignXAnimation.Duration = AlignmentTransitionDuration;
_alignYAnimation = _compositor.CreateScalarKeyFrameAnimation();
_alignYAnimation.Duration = AlignmentTransitionDuration;
// ZoomIn Animation Group
_scaleAnimation = _compositor.CreateVector3KeyFrameAnimation();
_scaleAnimation.Target = "Scale";
_scaleAnimation.InsertKeyFrame(1f, Vector3.One);
_scaleAnimation.Duration = TransitionDuration;
_zoomInAnimationGroup = _compositor.CreateAnimationGroup();
_zoomInAnimationGroup.Add(_scaleAnimation);
_zoomInAnimationGroup.Add(_offsetAnimation);
// Visuals
_rootContainer = _compositor.CreateContainerVisual();
_frameLayer = _compositor.CreateLayerVisual();
_frameBackgroundVisual = _compositor.CreateSpriteVisual();
_frameContentVisual = _compositor.CreateSpriteVisual();
_placeholderContentVisual = _compositor.CreateSpriteVisual();
_placeholderBackgroundVisual = _compositor.CreateSpriteVisual();
_nextVisualContent = _compositor.CreateSpriteVisual();
_frameLayer.Children.InsertAtTop(_frameBackgroundVisual);
_frameLayer.Children.InsertAtTop(_frameContentVisual);
_frameLayer.Children.InsertAtTop(_placeholderBackgroundVisual);
_frameLayer.Children.InsertAtTop(_placeholderContentVisual);
_frameLayer.Children.InsertAtTop(_nextVisualContent);
// Placeholder content
_placeholderContentMask = _generator.CreateGeometrySurface(PlaceholderSize, GetPlaceHolderGeometry(),
PlaceholderColor, PlaceholderBackground);
_placeholderContentBrush = _compositor.CreateSurfaceBrush(_placeholderContentMask.Surface);
_placeholderContentVisual.Brush = _placeholderContentBrush;
// Placeholder background
_placeholderBackgroundVisual.Brush = _compositor.CreateColorBrush(PlaceholderBackground);
// By default placeholder visual will not be visible
HidePlaceholder();
// Shadow visual
_shadowVisual = _compositor.CreateSpriteVisual();
_rootContainer.Children.InsertAtBottom(_shadowVisual);
_rootContainer.Children.InsertAtTop(_frameLayer);
_frameBackgroundVisual.Brush = _compositor.CreateColorBrush(FrameBackground);
// Create the effect to create the opacity mask
var layerEffect = new CompositeEffect
{
// CanvasComposite.DestinationIn - Intersection of source and mask.
// Equation: O = MA * S
// where O - Output pixel, MA - Mask Alpha, S - Source pixel.
Mode = CanvasComposite.DestinationIn,
Sources =
{
new CompositionEffectSourceParameter("source"),
new CompositionEffectSourceParameter("mask")
}
};
var layerEffectFactory = _compositor.CreateEffectFactory(layerEffect);
_layerEffectBrush = layerEffectFactory.CreateBrush();
// The mask for the imageFrame
_frameLayerMask = _generator.CreateMaskSurface(new Size(0, 0), null);
_layerEffectBrush.SetSourceParameter("mask", _compositor.CreateSurfaceBrush(_frameLayerMask.Surface));
// Apply the mask effect to the frameLayer
_frameLayer.Effect = _layerEffectBrush;
ElementCompositionPreview.SetElementChildVisual(this, _rootContainer);
}