private async void ShowCustomSplashScreen(Rect imageBounds) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; Vector2 windowSize = new Vector2((float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height); // // Create a container visual to hold the color fill background and image visuals. // Configure this visual to scale from the center. // ContainerVisual container = compositor.CreateContainerVisual(); container.Size = windowSize; container.CenterPoint = new Vector3(windowSize.X, windowSize.Y, 0) * .5f; ElementCompositionPreview.SetElementChildVisual(this, container); // // Create the colorfill sprite for the background, set the color to the same as app theme // SpriteVisual backgroundSprite = compositor.CreateSpriteVisual(); backgroundSprite.Size = windowSize; backgroundSprite.Brush = compositor.CreateColorBrush(Color.FromArgb(1, 0, 178, 240)); container.Children.InsertAtBottom(backgroundSprite); // // Create the image sprite containing the splash screen image. Size and position this to // exactly cover the Splash screen image so it will be a seamless transition between the two // CompositionDrawingSurface surface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Assets/SplashScreen.png")); SpriteVisual imageSprite = compositor.CreateSpriteVisual(); imageSprite.Brush = compositor.CreateSurfaceBrush(surface); imageSprite.Offset = new Vector3((float)imageBounds.X, (float)imageBounds.Y, 0f); imageSprite.Size = new Vector2((float)imageBounds.Width, (float)imageBounds.Height); container.Children.InsertAtTop(imageSprite); }
public VisualControl() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; Visual = _compositor.CreateSpriteVisual(); if (_surfaceFactoryInstance == null) { _surfaceFactoryInstance = SurfaceFactory.CreateFromCompositor(_compositor); } ElementCompositionPreview.SetElementChildVisual(this, Visual); SizeChanged += (sender, args) => { Visual.Size = new Vector2((float)args.NewSize.Width, (float)args.NewSize.Height); }; Unloaded += VisualControl_Unloaded; }
public BackDrop() { m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement); Compositor = m_rootVisual.Compositor; m_blurBrush = BuildBlurBrush(); m_blurBrush.SetSourceParameter("source", m_compositor.CreateBackdropBrush()); m_blurVisual = Compositor.CreateSpriteVisual(); m_blurVisual.Brush = m_blurBrush; BlurAmount = 9; TintColor = Colors.Transparent; ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual); this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
private void ShowVisual_Click(object sender, RoutedEventArgs e) { // Initialize the Compositor _compositor = new Compositor(); _root = ElementCompositionPreview.GetElementVisual(root); _compositor = _root.Compositor; // Generate the Green Square var colorVisual = _compositor.CreateSpriteVisual(); colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green); colorVisual.Size = new Vector2(150.0f, 150.0f); colorVisual.Offset = new Vector3(50.0f, 50.0f, 0.0f); // Add the image to the tree ElementCompositionPreview.SetElementChildVisual(root, colorVisual); _target = colorVisual; }
private void AddTextToRoot(BlendEffectMode blendEffectMode) { var redBrushWrapper = CreateTextToBrushWrapper(blendEffectMode.ToString(), Colors.Red); var blueBrushWrapper = CreateTextToBrushWrapper(blendEffectMode.ToString(), Colors.Cyan); blueBrushWrapper.Brush.Offset = new Vector2(-4f, 0); var blueMaskBrush = CreateGradientBrush(); var textVisual = Compositor.CreateSpriteVisual(); textVisual.Brush = CreateBrush(blueBrushWrapper.Brush, redBrushWrapper.Brush, blendEffectMode); textVisual.Size = new Vector2(400, 70); var background = new Rectangle { Height = 70, Width = 400 }; ElementCompositionPreview.SetElementChildVisual(background, textVisual); Root.Children.Add(background); }
/// <summary> ///初始化亚克力效果 ///需要在XAML的外层Grid中添加Span所有网格的内层Grid /// </summary> /// <param name="glassHost">内层Grid对象的名称</param> public static void InitializeFrostedGlass(UIElement glassHost) { Visual hostVisual = ElementCompositionPreview.GetElementVisual(glassHost); Compositor compositor = hostVisual.Compositor; var backdropBrush = compositor.CreateHostBackdropBrush(); var glassVisual = compositor.CreateSpriteVisual(); glassVisual.Brush = backdropBrush; ElementCompositionPreview.SetElementChildVisual(glassHost, glassVisual); var bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); glassVisual.StartAnimation("Size", bindSizeAnimation); //界面扩展到标题栏 CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false; var titlebar = ApplicationView.GetForCurrentView().TitleBar; titlebar.ButtonBackgroundColor = Colors.Transparent; }
public void PlayVideo(StorageFile file) { player.Source = MediaSource.CreateFromStorageFile(file); player.Play(); var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var surface = player.GetSurface(compositor); var surfaceBrush = compositor.CreateSurfaceBrush(surface.CompositionSurface); var hueEffect = new Microsoft.Graphics.Canvas.Effects.HueRotationEffect() { Name = "Hue", Source = new Windows.UI.Composition.CompositionEffectSourceParameter("source") }; var hueFactory = compositor.CreateEffectFactory(hueEffect, new string[] { "Hue.Angle" }); var hueBrush = hueFactory.CreateBrush(); hueBrush.SetSourceParameter("source", surfaceBrush); var spriteVisual = compositor.CreateSpriteVisual(); spriteVisual.Brush = surfaceBrush; ElementCompositionPreview.SetElementChildVisual(GridContent, spriteVisual); GridContent.SizeChanged += (o, e) => { spriteVisual.Size = new System.Numerics.Vector2((float)e.NewSize.Width, (float)e.NewSize.Height); }; var hueAnimation = compositor.CreateScalarKeyFrameAnimation(); hueAnimation.Duration = TimeSpan.FromMilliseconds(1000); hueAnimation.InsertKeyFrame(0f, (float)(0)); hueAnimation.InsertKeyFrame(1f, (float)(2 * Math.PI)); hueAnimation.IterationBehavior = Windows.UI.Composition.AnimationIterationBehavior.Forever; hueAnimation.StopBehavior = Windows.UI.Composition.AnimationStopBehavior.SetToInitialValue; //hueBrush.Properties.StartAnimation("Hue.Angle", hueAnimation); }
/// <summary> /// Initialize Composition /// </summary> private void InitializeComposition() { // Retrieve an instance of the Compositor from the backing Visual of the Page _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Create a root visual from the Compositor _root = _compositor.CreateContainerVisual(); // Set the root ContainerVisual as the XAML Page Visual ElementCompositionPreview.SetElementChildVisual(this, _root); // Assign initial values to variables used to store updated offsets for the visuals float posXUpdated = _posX; float posYUpdated = _posY; //Create a list of image brushes that can be applied to a visual string[] imageNames = { "60Banana.png", "60Lemon.png", "60Vanilla.png", "60Mint.png", "60Orange.png", "110Strawberry.png", "60SprinklesRainbow.png" }; _imageBrushList = new List <CompositionSurfaceBrush>(); _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); for (int k = 0; k < imageNames.Length; k++) { var surface = _imageLoader.LoadImageFromUri(new Uri("ms-appx:///Samples/SDK 14393/ImplicitAnimationTransformer/" + imageNames[k])); _imageBrushList.Add(_compositor.CreateSurfaceBrush(surface)); } // Create nxn matrix of visuals where n=row/ColumnCount-1 and passes random image brush to the function // that creates a visual for (int i = 1; i < _rowCount; i++) { posXUpdated = i * _distance; for (int j = 1; j < _columnCount; j++) { CompositionSurfaceBrush brush = _imageBrushList[randomBrush.Next(_imageBrushList.Count)]; posYUpdated = j * _distance; _root.Children.InsertAtTop(CreateChildElement(brush, posXUpdated, posYUpdated)); } } // Update the default animation state UpdateAnimationState(EnableAnimations.IsChecked == true); }
public ScrollViewerBackground() { if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { return; } IsTabStop = false; _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _visual = _compositor.CreateSpriteVisual(); ElementCompositionPreview.SetElementChildVisual(this, _visual); Loaded += OnLoaded; SizeChanged += OnSizeChanged; RegisterPropertyChangedCallback(BackgroundProperty, OnBackgroundChanged); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // Create Container Visual from Grid to be used as root of Visual Tree _root = ElementCompositionPreview.GetElementVisual(Placeholder); _compositor = _root.Compositor; // Create SpriteVisual with ColorBrush and insert into Visual Tree _mainVisual = _compositor.CreateSpriteVisual(); _mainVisual.Size = new Vector2(RectangleWidth, RectangleHeight); _mainVisual.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Blue); _mainVisual.CenterPoint = new Vector3(RectangleWidth / 2, RectangleHeight / 2, 0); float rectPositionX = (float)(-RectangleWidth / 2); float rectPositionY = (float)(-RectangleHeight / 2); _mainVisual.Offset = new Vector3(rectPositionX, rectPositionY, 0); ElementCompositionPreview.SetElementChildVisual(Placeholder, _mainVisual); }
private void Interaction() { _interactionTracker = InteractionTracker.Create(_compositor); _interactionTracker.MinScale = 0; _interactionTracker.MaxScale = 100f; _interactionTracker.MaxPosition = new Vector3((float)Window.Current.Bounds.Width * 0.5f, (float)Window.Current.Bounds.Height * 0.5f, 0f); _interactionTracker.MinPosition = new Vector3(); _interactionSource = VisualInteractionSource.Create(ElementCompositionPreview.GetElementVisual(Window.Current.Content)); _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionTracker.InteractionSources.Add(_interactionSource); var blurEffect = new GaussianBlurEffect { BlurAmount = 0f, Optimization = EffectOptimization.Speed, Name = "blurEffect", Source = new CompositionEffectSourceParameter("image") }; var effectFactory = _compositor.CreateEffectFactory(blurEffect, new[] { "blurEffect.BlurAmount" }); var blurBrush = effectFactory.CreateBrush(); blurBrush.SetSourceParameter("image", _compositor.CreateBackdropBrush()); _sprite = _compositor.CreateSpriteVisual(); _sprite.Size = new Vector2((float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height); _sprite.Brush = blurBrush; var blurAnimation = _compositor.CreateExpressionAnimation("lerp(tracker.MinScale, tracker.MaxScale, clamp(tracker.Position.X / width, 0, 1))"); blurAnimation.SetReferenceParameter("tracker", _interactionTracker); blurAnimation.SetScalarParameter("width", (float)Window.Current.Bounds.Width); _sprite.Brush.Properties.StartAnimation("blurEffect.BlurAmount", blurAnimation); ElementCompositionPreview.SetElementChildVisual(Image, _sprite); }
private void TextBlockMixedReality_LayoutUpdated( object sender, object e) { // Get compositor and create sprite visual var compositor = ElementCompositionPreview. GetElementVisual(MainGrid).Compositor; var visual = compositor.CreateSpriteVisual(); // Adjust visual size to text block size visual.Size = TextBlockMixedReality.DesiredSize.ToVector2(); // Create drop shadow visual.Shadow = CreateDropShadowForTextBlock( compositor, TextBlockMixedReality); // Add visual to the composition preview ElementCompositionPreview.SetElementChildVisual( MainGrid, visual); }
public void SetupVisual() { // Intialize the Compositor _compositor = new Compositor(); _root = ElementCompositionPreview.GetElementVisual(Container); _compositor = _root.Compositor; // Generate the Green Square var colorVisual = _compositor.CreateSpriteVisual(); colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green); colorVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f); colorVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f); // Add the Visual to the tree ElementCompositionPreview.SetElementChildVisual(Container, colorVisual); _target = colorVisual; }
/// <summary> /// Create the _backVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeBehindVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _backVisual, set the brush on it, and attach it to the BackGrid. BackGrid is an empty grid // that is visually behind the profile background (the waves). Therefore, setting it as the // child visual on the BackGrid will put it behind all the scrollViewer content. // _backVisual = _compositor.CreateSpriteVisual(); _backVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(BackGrid, _backVisual); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being after the crossover point. // _backVisual.Scale = new Vector3(_finalScaleAmount, _finalScaleAmount, 1); var scrollPropSet = scrollProperties.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var crossoverTranslation = ExpressionValues.Constant.CreateConstantScalar("CrossoverTranslation"); _behindOpacityExpression = EF.Conditional(-scrollPropSet.Translation.Y <= crossoverTranslation, 0, 1); // // "Terms" and explanation of the following expression: // // (initialOffset - scrollingProperties.Translation.Y) // // Since _backVisual is a child of the scroller, the initial position minus the scrolling offset keeps the content // in its original location. // // 2 * (CrossoverTranslation + scrollingProperties.Translation.Y) // // Since scrollingProperties.Translation.Y is negative when this expression is visibile, this term calculates the // distance past the crossover point and scales it. The scale causes the content to move faster than the scrolling. // Since this term evaluates to zero at the crossover point and the term above keeps the content from moving, when // the visibility swaps between frontVisual and backVisual, they are perfectly aligned. // var baseOffset = ExpressionValues.Constant.CreateConstantScalar("BaseOffset"); _behindTranslationExpression = (baseOffset - scrollPropSet.Translation.Y) + 2 * (crossoverTranslation + scrollPropSet.Translation.Y); }
public static Canvas CreateSnowBall(int x, double size, double duration, double delay, Size screenSize) { var container = new Canvas(); var compositor = ElementCompositionPreview.GetElementVisual(container).Compositor; var containerVisual = compositor.CreateContainerVisual(); var snow = new Ellipse() { Height = size, Width = size, Fill = new SolidColorBrush(Colors.White) }; var snowVisual = ElementCompositionPreview.GetElementVisual(snow); snowVisual.Offset = new Vector3(x, 0, 0); var animationOffset = compositor.CreateVector2KeyFrameAnimation(); animationOffset.InsertKeyFrame(0f, new Vector2(x, 0f)); animationOffset.InsertKeyFrame(1f, new Vector2(x, (float)screenSize.Height)); animationOffset.Duration = TimeSpan.FromSeconds(duration); animationOffset.DelayTime = TimeSpan.FromSeconds(delay); animationOffset.IterationBehavior = AnimationIterationBehavior.Forever; var animationFade = compositor.CreateScalarKeyFrameAnimation(); animationFade.InsertKeyFrame(0f, 1); animationFade.InsertKeyFrame(1f, 0); animationFade.Duration = TimeSpan.FromSeconds(duration); animationFade.DelayTime = TimeSpan.FromSeconds(delay); animationFade.IterationBehavior = AnimationIterationBehavior.Forever; snowVisual.StartAnimation("Offset.xy", animationOffset); snowVisual.StartAnimation("Opacity", animationFade); container.Children.Add(snow); containerVisual.Children.InsertAtTop(snowVisual); ElementCompositionPreview.SetElementChildVisual(container, containerVisual); return(container); }
public async Task <SpriteVisual[]> ApplyMultipleOverlaysAsync(Panel parentContainer, ItemsControl overlayTarget, Image backgroundImage, IEnumerable <Overlay> overlays) { var overlayArray = overlays as Overlay[] ?? overlays.ToArray(); if ((overlays == null) || !overlayArray.Any()) { return(null); } var spriteVisuals = new List <SpriteVisual>(); var bitmap = await CreateBackgroundBitmap(backgroundImage); var pixels = await bitmap.GetPixelsAsync(); var dpi = DisplayInformation.GetForCurrentView().LogicalDpi; // as we want to add multiple overlay visuals, we need to add them to // a container visual first. // we then add the container visual to the target element. var targetContainerVisual = _compositor.CreateContainerVisual(); ; foreach (var overlay in overlayArray) { var areaToRender = DetermineAreaToRender(parentContainer, overlayTarget, overlay.OverlayTargetRect); var backgroundImageBrush = CreateBackgroundBrush(pixels, bitmap, dpi, areaToRender); var opacityBrush = await CreateOpacityMaskBrush(overlay.OverlayMaskImageUri); var maskbrush = CreateMaskBrush(opacityBrush, backgroundImageBrush); var maskSprite = CreateMaskSprite(overlay.OverlayTargetRect, maskbrush); maskSprite.Opacity = overlay.InitialRenderTransparent ? 0.0f : 1.0f; targetContainerVisual.Children.InsertAtTop(maskSprite); spriteVisuals.Add(maskSprite); } ElementCompositionPreview.SetElementChildVisual(overlayTarget, targetContainerVisual); return(spriteVisuals.ToArray()); }
private void BuildBackground() { var compositor = Window.Current.Compositor; _effectVisual = compositor.CreateSpriteVisual(); //var graphicsEffect = new GaussianBlurEffect //{ // BlurAmount = 34, // BorderMode = EffectBorderMode.Hard, // Source = new CompositionEffectSourceParameter("Background") //}; var graphicsEffect = new BlendEffect { Mode = BlendEffectMode.SoftLight, Background = new ColorSourceEffect { Color = Colors.LightCyan }, Foreground = new GaussianBlurEffect { BlurAmount = 34, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("Background") } }; var effectFactory = compositor.CreateEffectFactory(graphicsEffect); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("Background", compositor.CreateBackdropBrush()); _effectVisual.Brush = effectBrush; // set the size! ResizeVisual(); ElementCompositionPreview.SetElementChildVisual(EffectUiHostBackground, _effectVisual); }
// Draw repeating pattern texture on backgound canvas. public async Task SetupBackgroundPatternAsync() { var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var canvasDevice = CanvasDevice.GetSharedDevice(); var graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice); var bitmap = await CanvasBitmap.LoadAsync(canvasDevice, @"Assets\BackgroundPattern.png"); var drawingSurface = graphicsDevice.CreateDrawingSurface( bitmap.Size, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(drawingSurface)) { ds.Clear(Colors.Transparent); ds.DrawImage(bitmap); } var surfaceBrush = compositor.CreateSurfaceBrush(drawingSurface); surfaceBrush.Stretch = CompositionStretch.None; var border = new BorderEffect { ExtendX = CanvasEdgeBehavior.Wrap, ExtendY = CanvasEdgeBehavior.Wrap, Source = new CompositionEffectSourceParameter("source"), }; var fxFactory = compositor.CreateEffectFactory(border); var fxBrush = fxFactory.CreateBrush(); fxBrush.SetSourceParameter("source", surfaceBrush); var sprite = compositor.CreateSpriteVisual(); sprite.Size = new Vector2(4096); sprite.Brush = fxBrush; ElementCompositionPreview.SetElementChildVisual(_canvas, sprite); }
private void UpdateShadow(PancakeView pancake) { //For now gets the shadow only when the CornerRadius has the same value for all sides. if (Control != null && pancake.Shadow != null && pancake.Width > 0 && pancake.Height > 0 && pancake.CornerRadius.TopLeft == pancake.CornerRadius.BottomRight && pancake.CornerRadius.TopLeft == pancake.CornerRadius.BottomLeft && pancake.CornerRadius.BottomRight == pancake.CornerRadius.TopRight) { rectangle.Fill = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Black); rectangle.Width = pancake.Width; rectangle.Height = pancake.Height; rectangle.RadiusX = pancake.CornerRadius.TopRight + 5; rectangle.RadiusY = pancake.CornerRadius.TopRight + 5; var compositor = ElementCompositionPreview.GetElementVisual(rectangle).Compositor; visual = compositor.CreateSpriteVisual(); visual.Size = new Vector2((float)pancake.Width, (float)pancake.Height); var shadow = compositor.CreateDropShadow(); shadow.BlurRadius = pancake.Shadow.BlurRadius; shadow.Mask = rectangle.GetAlphaMask(); shadow.Opacity = pancake.Shadow.Opacity; shadow.Color = pancake.Shadow.Color.ToWindowsColor(); shadow.Offset = new Vector3((float)pancake.Shadow.Offset.X, (float)pancake.Shadow.Offset.Y, 0); visual.Shadow = shadow; ElementCompositionPreview.SetElementChildVisual(rectangle, visual); } else { if (rectangle != null) { rectangle.Fill = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent); } if (visual != null) { visual.Shadow = null; ElementCompositionPreview.SetElementChildVisual(rectangle, null); } } }
public void SetupVisual() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var myVisual = ElementCompositionPreview.GetElementChildVisual(RedRobot); //myVisual.Size = new System.Numerics.Vector2(x: (float) RedRobot.ActualHeight, // y: (float) RedRobot.ActualWidth); // myVisual.Offset = new System.Numerics.Vector3(30, 30, 0); ; // create a blue drop shadow //var s = new CompositionEffectBrush // .CreateDropShadow is part of the Win2D.uwp NuGet package // need to add a reference to GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 10.0f, // You can place your blur amount here. BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("source") }; var effectFactory = _compositor.CreateEffectFactory(graphicsEffect: blurEffect, animatableProperties: new[] { nameof(GaussianBlurEffect.BlurAmount) }); var effectBrush = effectFactory.CreateBrush(); var surfaceBrush = _compositor.CreateSurfaceBrush(); effectBrush.SetSourceParameter(name: "source", source: _compositor.CreateBackdropBrush()); // https://stackoverflow.com/questions/46052953/uwp-create-shadow-in-xaml // https://stackoverflow.com/questions/36276856/uwp-app-realtime-blur-background-using-dx-compositor/36441888 //https://stackoverflow.com/questions/40035604/how-to-apply-a-simple-blur-effect //var shadow = _compositor.CreateDropShadow() //shadow.Offset = new System.Numerics.Vector3(30, 30, 0); //shadow.Color = Colors.Blue; //myVisual.Shadow = shadow; // render on page ElementCompositionPreview.SetElementChildVisual(this, myVisual); }
public DropShadowEffect() { this.InitializeComponent(); var compositor = ElementCompositionPreview.GetElementVisual(rootgrid).Compositor; var spriteVisual = compositor.CreateSpriteVisual(); spriteVisual.Size = new Vector2(400, 300); var dropShadow = compositor.CreateDropShadow(); dropShadow.Offset = new Vector3(15, 15, 0); dropShadow.Color = new Windows.UI.Color() { A = 20, R = 0, G = 0, B = 0 }; spriteVisual.Shadow = dropShadow; ElementCompositionPreview.SetElementChildVisual(rootgrid, spriteVisual); }
private void SetupComposition() { if (DesignMode.DesignModeEnabled) { return; } HostVisual = ElementCompositionPreview.GetElementVisual(ShadowHost); _Compositor = HostVisual.Compositor; _ShadowVisual = _Compositor.CreateSpriteVisual(); _ShadowVisual.BindSize(HostVisual); _Shadow = _Compositor.CreateDropShadow(); _Shadow.Offset = Vector3.Zero; _Shadow.BlurRadius = 25f; _ShadowVisual.Shadow = _Shadow; ElementCompositionPreview.SetElementChildVisual(ShadowHost, _ShadowVisual); }
public OutlineTextControl() { var graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(Compositor, CanvasDevice.GetSharedDevice()); var spriteTextVisual = Compositor.CreateSpriteVisual(); ElementCompositionPreview.SetElementChildVisual(this, spriteTextVisual); SizeChanged += (s, e) => { DrawingSurface = graphicsDevice.CreateDrawingSurface(e.NewSize, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); DrawSurface(); UpdateSpriteVisual(spriteTextVisual, DrawingSurface); spriteTextVisual.Size = e.NewSize.ToVector2(); }; RegisterPropertyChangedCallback(FontSizeProperty, new DependencyPropertyChangedCallback((s, e) => { DrawSurface(); })); }
// This is only get called by ItemDetailsPage.Episodesitem_ContainerContentChanging public async void LoadImage() { ThumbnailCompositor = ElementCompositionPreview.GetElementVisual(Thumbnail).Compositor; using var stream = await GetImage(); ThumbnailSurface = LoadedImageSurface.StartLoadFromStream(stream); ThumbnailSurface.LoadCompleted += ImgSurface_LoadCompleted; ThumbnailSurfaceBrush = ThumbnailCompositor.CreateSurfaceBrush(ThumbnailSurface); ThumbnailSurfaceBrush.BitmapInterpolationMode = CompositionBitmapInterpolationMode.Linear; ThumbnailSurfaceBrush.Stretch = CompositionStretch.UniformToFill; ThumbnailSpriteVisual = ThumbnailCompositor.CreateSpriteVisual(); ThumbnailSpriteVisual.Brush = ThumbnailSurfaceBrush; ThumbnailSpriteVisual.Opacity = 0; ThumbnailSpriteVisual.Size = new Vector2(180, 80); ElementCompositionPreview.SetElementChildVisual(Thumbnail, ThumbnailSpriteVisual); }
/// <summary> /// Initializes a new instance of the <see cref="BackDrop" /> class. /// </summary> public BackDrop() { var rootVisual = ElementCompositionPreview.GetElementVisual(this); _compositor = rootVisual.Compositor; _blurVisual = _compositor.CreateSpriteVisual(); var brush = BuildBlurBrush(); brush.SetSourceParameter("Source", _compositor.CreateBackdropBrush()); _blurBrush = brush; _blurVisual.Brush = _blurBrush; TintColor = Colors.Transparent; ElementCompositionPreview.SetElementChildVisual(this, _blurVisual); Loading += OnLoading; Unloaded += OnUnloaded; }
private void LoadMazeRunnerVisual() { if (_mazeRunnerVisual != null) { _mazeRunnerVisual.Dispose(); } _mazeRunnerVisual = _compositor.CreateSpriteVisual(); _mazeRunnerVisual.Size = new Vector2(_cellSize, _cellSize); LoadedImageSurface loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/luna.png"), new Size(_cellSize, _cellSize)); CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(); surfaceBrush.Surface = loadedSurface; _mazeRunnerVisual.Brush = surfaceBrush; ElementCompositionPreview.SetElementChildVisual(MazeGrid, _mazeRunnerVisual); _mazeRunnerVisual.IsVisible = true; _mazeRunnerVisual.Opacity = 1; }
public void UpdateEffect() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 100.0f, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("source"), }; var fac = _compositor.CreateEffectFactory(blurEffect); var brush = fac.CreateBrush(); var backdropbrush = _compositor.CreateHostBackdropBrush(); brush.SetSourceParameter("source", backdropbrush); _spriteVisual = _compositor.CreateSpriteVisual(); _spriteVisual.Brush = brush; _spriteVisual.Size = new System.Numerics.Vector2((float)backgroundGrid.ActualWidth, (float)backgroundGrid.ActualHeight); ElementCompositionPreview.SetElementChildVisual(backgroundGrid, _spriteVisual); }
public Backdrop() { DefaultStyleKey = typeof(Backdrop); SizeChanged += (sender, e) => { UpdateVisualSize(); }; var rootVisual = ElementCompositionPreview.GetElementVisual(this); _compositor = rootVisual.Compositor; _blurVisual = _compositor.CreateSpriteVisual(); var brush = CreateBlurBrush(); brush.SetSourceParameter("Source", _compositor.CreateBackdropBrush()); _blurVisual.Brush = brush; ElementCompositionPreview.SetElementChildVisual(this, _blurVisual); }
private void Dispose() { if (_surface != null) { ElementCompositionPreview.SetElementChildVisual(_surface, null); _surface = null; } if (_surfaceVisual != null) { _surfaceVisual.Brush = null; _surfaceVisual = null; } if (_mediaPlayer?.Source != null) { _mediaPlayer.MediaPlayer.Pause(); _mediaPlayer.Source = null; } }
private void OnLoaded(object sender, RoutedEventArgs e) { if (!_hasInitialLoadedEventFired) { _visual = ElementCompositionPreview.GetElementVisual(_presenter); _hitTest = _visual.Compositor.CreateSpriteVisual(); _hitTest.Brush = _visual.Compositor.CreateColorBrush(Windows.UI.Colors.Transparent); _container = _visual.Compositor.CreateContainerVisual(); _container.Children.InsertAtBottom(_hitTest); _container.Size = _hitTest.Size = new Vector2((float)ActualWidth, (float)ActualHeight); ElementCompositionPreview.SetElementChildVisual(this, _container); ConfigureInteractionTracker(); } _hasInitialLoadedEventFired = true; }