■ Compositor 클래스의 CreateLinearGradientBrush 메소드를 사용해 CompositionLinearGradientBrush 객체를 만드는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
using System.Numerics; using Microsoft.UI; using Microsoft.UI.Composition; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Hosting; // ... Grid grid; // ... Visual gridVisual = ElementCompositionPreview.GetElementVisual(grid); Compositor compositor = gridVisual.Compositor; SpriteVisual spriteVisual = compositor.CreateSpriteVisual(); spriteVisual.Size = new Vector2((float)grid.ActualWidth, (float)grid.ActualHeight); ElementCompositionPreview.SetElementChildVisual(grid, spriteVisual); CompositionLinearGradientBrush compositionLinearGradientBrush = compositor.CreateLinearGradientBrush(); compositionLinearGradientBrush.StartPoint = new Vector2(0, 0); compositionLinearGradientBrush.EndPoint = new Vector2(1, 1); CompositionColorGradientStop compositionColorGradientStop1 = compositor.CreateColorGradientStop(0.0f, Colors.Transparent); CompositionColorGradientStop compositionColorGradientStop2 = compositor.CreateColorGradientStop(1.0f, Colors.Blue ); compositionLinearGradientBrush.ColorStops.Add(compositionColorGradientStop1); compositionLinearGradientBrush.ColorStops.Add(compositionColorGradientStop2); spriteVisual.Brush = compositionLinearGradientBrush; |