本文整理汇总了C#中Compositor.CreateDropShadow方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateDropShadow方法的具体用法?C# Compositor.CreateDropShadow怎么用?C# Compositor.CreateDropShadow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compositor
的用法示例。
在下文中一共展示了Compositor.CreateDropShadow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SamplePage_Loaded
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// Get backing visual from shadow container and interop compositor
_shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
_compositor = _shadowContainer.Compositor;
// Get CompositionImage, its sprite visual
_image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer);
_imageVisual = _image.SpriteVisual;
// Add drop shadow to image visual
_shadow = _compositor.CreateDropShadow();
_imageVisual.Shadow = _shadow;
// Initialize sliders to shadow defaults - with the exception of offset
BlurRadiusSlider.Value = _shadow.BlurRadius; //defaults to 9.0f
OffsetXSlider.Value = _shadow.Offset.X; //defaults to 0
OffsetYSlider.Value = _shadow.Offset.Y; //defaults to 0
RedSlider.Value = _shadow.Color.R; //defaults to 0 (black.R)
GreenSlider.Value = _shadow.Color.G; //defaults to 0 (black.G)
BlueSlider.Value = _shadow.Color.B; //defaults to 0 (black.B)
// Load mask asset onto surface using helpers in SamplesCommon
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
_imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png"));
// Create surface brush for mask
CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
mask.Surface = _imageMaskSurface.Surface;
// Get surface brush from composition image
CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;
// Create mask brush for toggle mask functionality
_maskBrush = _compositor.CreateMaskBrush();
_maskBrush.Mask = mask;
_maskBrush.Source = source;
// Initialize toggle mask and animation to false
_isMaskEnabled = false;
_isAnimationEnabled = false;
}
示例2: GetSharedShadow
/// <summary>
/// Gets the instance of the shared DropShadow
/// </summary>
/// <param name="compositor">Compositor</param>
/// <returns>DropShadow</returns>
internal static DropShadow GetSharedShadow(Compositor compositor)
{
if (_sharedShadow == null)
{
lock (ShadowLock)
{
if (_sharedShadow == null)
{
_sharedShadow = compositor.CreateDropShadow();
}
}
}
return _sharedShadow;
}
示例3: InitShadow
private void InitShadow()
{
grdLowerLayer.UpdateLayout();
_shadowContainer = CompositionManager.GetVisual(grdLowerLayer);
_shadowContainer.Size = new Vector2((float)grdLowerLayer.ActualWidth, (float)grdLowerLayer.ActualHeight);
_shadowContainer.Offset = new Vector3(0, 0, 0);
_compositor = CompositionManager.GetCompositor(_shadowContainer);
_spriteVisual = _compositor.CreateSpriteVisual();
_spriteVisual.Size = new Vector2((float)grdLowerLayer.ActualWidth + 10, (float)grdLowerLayer.ActualHeight + 10);
_spriteVisual.Offset = new Vector3(-5, -5, 0);
// Add drop shadow to image visual
_shadow = _compositor.CreateDropShadow();
_shadow.Offset = new System.Numerics.Vector3(0, 0, 0);
_shadow.Color = Windows.UI.Colors.Black;
_shadow.Opacity = 0.3f;
_spriteVisual.Shadow = _shadow;
_shadowContainer.Children.InsertAtBottom(_spriteVisual);
}
示例4: OnLoaded
private async void OnLoaded(object sender, RoutedEventArgs e)
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
_backdropBrush = _compositor.CreateBackdropBrush();
_width = 300f;
_height = 300f;
// Create the combined geometry
var ellipse1 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.45f * _width, 0.225f * _height);
var ellipse2 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.225f * _width, 0.45f * _height);
_combinedGeometry = ellipse1.CombineWith(ellipse2, Matrix3x2.Identity, CanvasGeometryCombine.Union);
// Create the container to host the visuals
var container1 = _compositor.CreateContainerVisual();
container1.Size = new Vector2(CompositionGrid1.ActualWidth.Single(), CompositionGrid1.ActualHeight.Single());
// Background Visual
_bgVisual1 = _compositor.CreateSpriteVisual();
_bgVisual1.Size = new Vector2(_width * 0.45f, _height * 0.45f);
_bgVisual1.Offset = new Vector3(((CompositionGrid1.ActualWidth - _width) / 2).Single(),
((CompositionGrid1.ActualHeight - _height) / 2).Single(), 0);
_bgVisual1.Brush = _compositor.CreateColorBrush(Colors.DarkOrange);
container1.Children.InsertAtBottom(_bgVisual1);
// Create custom shaped visual using CompositionMaskBrush
_visual1 = _compositor.CreateSpriteVisual();
_visual1.Size = new Vector2(_width, _height);
_visual1.Offset = new Vector3(((CompositionGrid1.ActualWidth - _width) / 2).Single(),
((CompositionGrid1.ActualHeight - _height) / 2).Single(), 0);
// Create the CompositionMask
var ellipseGeometry = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.4f * _width, 0.4f * _height);
var compositionMask = _generator.CreateMaskSurface(_visual1.Size.ToSize(), ellipseGeometry);
// Create Masked BackdropBrush from CompositionMask
_visual1.Brush = _compositor.CreateMaskedBackdropBrush(compositionMask, Colors.AntiqueWhite, 30f, _backdropBrush);
container1.Children.InsertAtTop(_visual1);
var visual = _compositor.CreateSpriteVisual();
visual.Size = new Vector2(400, 400);
visual.Offset = new Vector3(((3 * CompositionGrid1.ActualWidth / 4f) - (_width / 2)).Single(),
((3 * CompositionGrid1.ActualHeight / 4f) - (_height / 2)).Single(), 0);
var roundRectGeometry = CanvasGeometry.CreateRoundedRectangle(_generator.Device, 0, 0, _width, _height, 25, 25);
var maskSurface = _generator.CreateMaskSurface(visual.Size.ToSize(), roundRectGeometry);
var frostedBrush = _compositor.CreateFrostedGlassBrush(maskSurface, Colors.AntiqueWhite, 30f, _backdropBrush);
var shadow = _compositor.CreateDropShadow();
shadow.Opacity = 0.5f;
shadow.Color = Colors.Black;
shadow.Offset = new Vector3(10, 10, 0);
shadow.BlurRadius = 15;
shadow.Mask = frostedBrush.GetSourceParameter("mask");
visual.Brush = frostedBrush;
visual.Shadow = shadow;
container1.Children.InsertAtTop(visual);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, container1);
// Initialize the visuals for the Animated Canvas
// Create the container to host the visuals
var container2 = _compositor.CreateContainerVisual();
container2.Size = new Vector2(CompositionGrid2.ActualWidth.Single(), CompositionGrid2.ActualHeight.Single());
// Background Visual
_bgVisual2 = _compositor.CreateSpriteVisual();
_bgVisual2.Size = new Vector2(_width * Factor, _height * Factor);
_bgVisual2.Offset = new Vector3(((CompositionGrid2.ActualWidth - (_width * Factor)) / 2).Single(),
((CompositionGrid2.ActualHeight - (_height * Factor)) / 2).Single(), 0);
//var radians = ((45f * Math.PI) / 180).Single();
//var bgGeometry = _combinedGeometry.Transform(Matrix3x2.CreateRotation(radians, new Vector2(_width / 2, _height / 2)));
//var bgMask = await _generator.CreateMaskAsync(_bgVisual2.Size.ToSize(), bgGeometry, Colors.DarkRed);
//_bgVisual2.Brush = _compositor.CreateSurfaceBrush(bgMask.Surface);
_bgVisual2.Brush = _compositor.CreateColorBrush(Colors.LawnGreen);
container2.Children.InsertAtBottom(_bgVisual2);
// Animated Visual
_animatedVisual = _compositor.CreateSpriteVisual();
_animatedVisual.Size = new Vector2(_width, _height);
_animatedVisual.Offset = new Vector3(((CompositionGrid2.ActualWidth - _width) / 2).Single(),
((CompositionGrid2.ActualHeight - _height) / 2).Single(), 0);
// Create the Excluded geometry
_outerGeometry = CanvasGeometry.CreateRectangle(_generator.Device, 0, 0, _width, _height);
var excludedGeometry = _outerGeometry.CombineWith(_combinedGeometry, Matrix3x2.Identity, CanvasGeometryCombine.Exclude);
// Create the CompositionMask
_animatedCompositionMask = _generator.CreateMaskSurface(_animatedVisual.Size.ToSize(), excludedGeometry);
var animBrush = _compositor.CreateMaskedBackdropBrush(_animatedCompositionMask, Colors.AntiqueWhite, 10f, _backdropBrush);
_animatedVisual.Brush = animBrush;
container2.Children.InsertAtTop(_animatedVisual);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, container2);
}