当前位置: 首页>>代码示例>>C#>>正文


C# Compositor.CreateFrostedGlassBrush方法代码示例

本文整理汇总了C#中Compositor.CreateFrostedGlassBrush方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateFrostedGlassBrush方法的具体用法?C# Compositor.CreateFrostedGlassBrush怎么用?C# Compositor.CreateFrostedGlassBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compositor的用法示例。


在下文中一共展示了Compositor.CreateFrostedGlassBrush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
        }
开发者ID:RareNCool,项目名称:CompositionProToolkit,代码行数:99,代码来源:MaskedBackdropPage.xaml.cs


注:本文中的Compositor.CreateFrostedGlassBrush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。