本文整理汇总了C#中Compositor.CreateLayerVisual方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateLayerVisual方法的具体用法?C# Compositor.CreateLayerVisual怎么用?C# Compositor.CreateLayerVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compositor
的用法示例。
在下文中一共展示了Compositor.CreateLayerVisual方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateVisuals
public void CreateVisuals(Compositor compositor)
{
layerVisual = compositor.CreateLayerVisual();
itemContainerVisual = compositor.CreateContainerVisual();
layerVisual.Children.InsertAtTop(itemContainerVisual);
for (int i = 0; i < items.Count; ++i)
{
var item = items[i];
var itemVisual = item.CreateVisual(compositor);
itemVisual.Size = new Vector2(300, 200);
itemVisual.Offset = new Vector3((i % 2 - 1) * itemVisual.Size.X, (i / 2 - 1) * itemVisual.Size.Y, 0);
itemContainerVisual.Children.InsertAtTop(itemVisual);
}
}
示例2: InitializeComposition
/// <summary>
/// Initialize all Composition related stuff here (Compositor, Animations etc)
/// </summary>
private void InitializeComposition()
{
var rootVisual = ElementCompositionPreview.GetElementVisual(this);
// Compositor
_compositor = rootVisual.Compositor;
// Composition Generator
_generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
// Final Value Expressions
var vector3Expr = _compositor.CreateFinalValueExpression<Vector3>();
var scalarExpr = _compositor.CreateFinalValueExpression<float>();
// Opacity Animation
var opacityAnimation = _compositor.CreateKeyFrameAnimation<float>()
.HavingDuration(DefaultOpacityAnimationDuration)
.ForTarget(() => rootVisual.Opacity);
opacityAnimation.InsertExpressionKeyFrame(1f, scalarExpr);
// Scale Animation
var scaleAnimation = _compositor.CreateKeyFrameAnimation<Vector3>()
.HavingDuration(DefaultScaleAnimationDuration)
.ForTarget(() => rootVisual.Scale);
scaleAnimation.InsertExpressionKeyFrame(1f, vector3Expr);
// ImplicitAnimation
_implicitAnimationCollection = _compositor.CreateImplicitAnimationCollection();
_implicitAnimationCollection["Opacity"] = opacityAnimation.Animation;
_implicitAnimationCollection["Scale"] = scaleAnimation.Animation;
// Expand Animations
_expandLeftInset = _compositor.CreateKeyFrameAnimation<float>()
.HavingDuration(InsetAnimationDuration)
.DelayBy(InsetAnimationDelayDuration);
_expandLeftInset.InsertKeyFrame(1f, 0);
_expandRightInset = _compositor.CreateKeyFrameAnimation<float>()
.HavingDuration(InsetAnimationDuration)
.DelayBy(InsetAnimationDelayDuration);
_expandInsetClip = _compositor.CreateKeyFrameAnimation<float>()
.HavingDuration(InsetClipAnimationDuration);
_expandInsetClip.InsertKeyFrame(1f, 0);
// Collapse Animations
_collapseLeftInset = _compositor.CreateKeyFrameAnimation<float>()
.HavingDuration(InsetAnimationDuration);
_collapseRightInset = _compositor.CreateKeyFrameAnimation<float>()
.HavingDuration(InsetAnimationDuration);
_collapseInsetClip = _compositor.CreateKeyFrameAnimation<float>()
.HavingDuration(InsetClipAnimationDuration);
// Root Container
_rootContainer = _compositor.CreateContainerVisual();
// Background Layer
_bgLayer = _compositor.CreateLayerVisual();
_bgLayer.Size = _rootContainer.Size;
_bgLayer.CenterPoint = new Vector3(_bgLayer.Size * 0.5f, 0);
// Top Layer
_topLayer = _compositor.CreateLayerVisual();
_topLayer.Size = _rootContainer.Size;
_rootContainer.Children.InsertAtBottom(_bgLayer);
_rootContainer.Children.InsertAtTop(_topLayer);
// Add the rootContainer to the visual tree
ElementCompositionPreview.SetElementChildVisual(this, _rootContainer);
}
示例3: 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);
}