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

■ TappedRoutedEventArgs 클래스 : Handled 속성 사용하기

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


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 Name="rootGrid"

        Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

        <TextBlock

            HorizontalAlignment="Left"

            VerticalAlignment="Top"

            Text="Left / Top"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Center"

            VerticalAlignment="Top"

            Text="Center / Top"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Right"

            VerticalAlignment="Top"

            Text="Right / Top"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Left"

            VerticalAlignment="Center"

            Text="Left / Center"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Center"

            VerticalAlignment="Center"

            Text="Center / Center"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Right"

            VerticalAlignment="Center"

            Text="Right / Center"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Left"

            VerticalAlignment="Bottom"

            Text="Left / Bottom"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Center"

            VerticalAlignment="Bottom"

            Text="Center / Bottom"

            Tapped="textBlock_Tapped" />

        <TextBlock

            HorizontalAlignment="Right"

            VerticalAlignment="Bottom"

            Text="Right / Bottom"

            Tapped="textBlock_Tapped" />

    </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

        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        //////////////////////////////////////////////////////////////////////////////// Function

 

        #region 탭 처리하기 - OnTapped(e)

 

        /// <summary>

        /// 탭 처리하기

        /// </summary>

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

        protected override void OnTapped(TappedRoutedEventArgs e)

        {

            this.rootGrid.Background = GetBrush();

 

            base.OnTapped(e);

        }

 

        #endregion

 

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

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

 

        #region 텍스트 블럭 탭 처리하기 - textBlock_Tapped(sender, e)

 

        /// <summary>

        /// 텍스트 블럭 탭 처리하기

        /// </summary>

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

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

        private void textBlock_Tapped(object sender, TappedRoutedEventArgs e)

        {

            TextBlock textBlock = sender as TextBlock;

 

            textBlock.Foreground = GetBrush();

 

            e.Handled = true;

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////// Function

 

        #region 브러시 구하기 - GetBrush()

 

        /// <summary>

        /// 브러시 구하기

        /// </summary>

        /// <returns>브러시</returns>

        private Brush GetBrush()

        {

            this.random.NextBytes(this.colorByteArray);

 

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

 

            return new SolidColorBrush(color);

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요