첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ UIElement 클래스 : 라우팅 이벤트 사용하기

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


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="24">

    <Grid

        Margin="10"

        Background="{StaticResource ApplicationPageBackgroundThemeBrush}"

        Tapped="grid_Tapped">

        <TextBlock

            HorizontalAlignment="Left"

            VerticalAlignment="Top"

            Text="Left / Top" />

        <TextBlock

            HorizontalAlignment="Center"

            VerticalAlignment="Top"

            Text="Center / Top" />

        <TextBlock

            HorizontalAlignment="Right"

            VerticalAlignment="Top"

            Text="Right / Top" />

        <TextBlock

            HorizontalAlignment="Left"

            VerticalAlignment="Center"

            Text="Left / Center" />

        <TextBlock

            HorizontalAlignment="Center"

            VerticalAlignment="Center"

            Text="Center / Center" />

        <TextBlock

            HorizontalAlignment="Right"

            VerticalAlignment="Center"

            Text="Right / Center" />

        <TextBlock

            HorizontalAlignment="Left"

            VerticalAlignment="Bottom"

            Text="Left / Bottom" />

        <TextBlock

            HorizontalAlignment="Center"

            VerticalAlignment="Bottom"

            Text="Center / Bottom" />

        <TextBlock

            HorizontalAlignment="Right"

            VerticalAlignment="Bottom"

            Text="Right / Bottom" />

    </Grid>

</Page>

 

 

MainPage.xaml.cs

 

 

using System;

using Windows.UI;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Input;

using Windows.UI.Xaml.Media;

 

namespace TestProject

{

    /// <summary>

    /// 메인 페이지

    /// </summary>

    public sealed partial class MainPage : Page

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Field

 

        /// <summary>

        /// 난수 발생기

        /// </summary>

        private Random random = new Random();

 

        /// <summary>

        /// 색상 바이트 배열

        /// </summary>

        private byte[] colorByteArray = new byte[3];

 

        #endregion

 

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

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

 

        #region 생성자 - MainPage()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainPage()

        {

            InitializeComponent();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

        #region 그리드 탭 처리하기 - grid_Tapped(sender, e)

 

        /// <summary>

        /// 그리드 탭 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void grid_Tapped(object sender, TappedRoutedEventArgs e)

        {

            if(e.OriginalSource is TextBlock)

            {

                TextBlock textBlock = e.OriginalSource as TextBlock;

 

                this.random.NextBytes(this.colorByteArray);

 

                Color color = Color.FromArgb(255, this.colorByteArray[0], this.colorByteArray[1], this.colorByteArray[2]);

 

                textBlock.Foreground = new SolidColorBrush(color);

            }

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG ,

댓글을 달아 주세요