■ LinearGradientBrush 클래스 : GradientStops 속성 사용하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainPage.xaml

 

 

<Page x:Class="TestProject.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Grid Name="rootGrid"

        Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

        <TextBlock Name="textBlock"

            HorizontalAlignment="Center"

            VerticalAlignment="Center"

            FontSize="96"

            FontWeight="Bold"

            Text="Windows 10" />

    </Grid>

</Page>

 

 

MainPage.xaml.cs

 

 

using Windows.Foundation;

using Windows.UI;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Media;

 

namespace TestProject

{

    /// <summary>

    /// 메인 페이지

    /// </summary>

    public sealed partial class MainPage : Page

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainPage()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainPage()

        {

            InitializeComponent();

 

            #region 전경 브러시를 설정한다.

 

            LinearGradientBrush foregroundBrush = new LinearGradientBrush();

 

            foregroundBrush.StartPoint = new Point(0, 0);

            foregroundBrush.EndPoint   = new Point(1, 0);

 

            GradientStop gradientStop1 = new GradientStop();

 

            gradientStop1.Offset = 0;

            gradientStop1.Color  = Colors.Blue;

 

            foregroundBrush.GradientStops.Add(gradientStop1);

 

            GradientStop gradientStop2 = new GradientStop();

 

            gradientStop2.Offset = 1;

            gradientStop2.Color  = Colors.Red;

 

            foregroundBrush.GradientStops.Add(gradientStop2);

 

            #endregion

            #region 배경 브러시를 설정한다.

 

            LinearGradientBrush backgroundBrush = new LinearGradientBrush

            {

                 StartPoint = new Point(0, 0),

                 EndPoint   = new Point(1, 0)

            };

 

            backgroundBrush.GradientStops.Add(new GradientStop

            {

                Offset = 0,

                Color  = Colors.Red

            });

 

            backgroundBrush.GradientStops.Add(new GradientStop

            {

                Offset = 1,

                Color  = Colors.Blue

            });

 

            #endregion

 

            this.textBlock.Foreground = foregroundBrush;

            this.rootGrid.Background  = backgroundBrush;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요