첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

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 Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <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>

 

728x90

 

▶ 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.random.NextBytes(this.colorByteArray);

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

            SolidColorBrush brush = new SolidColorBrush(color);

            if(e.OriginalSource is TextBlock)
            {
                (e.OriginalSource as TextBlock).Foreground = brush;
            }
            else if(e.OriginalSource is Grid)
            {
                (e.OriginalSource as Grid).Background = brush;
            }

            base.OnTapped(e);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker
TAG , ,

댓글을 달아 주세요