첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainPageFunction.xaml

<PageFunction x:Class="TestProject.MainPageFunction"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    x:TypeArguments="sys:String"
    Title="메인 페이지 함수" 
    RemoveFromJournal="True">
    <Grid
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition              />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition               />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0"
            VerticalAlignment="Center">
            입력 항목
        </TextBlock>
        <TextBox Name="textBox" Grid.Row="0" Grid.Column="1"
            Margin="10 0 0 0"
            Width="150"
            Height="25"
            VerticalContentAlignment="Center" />
        <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
            Margin="0 10 0 0"
            Orientation="Horizontal"
            HorizontalAlignment="Center">
            <Button Name="okButton"
                Width="60"
                Height="30"
                IsDefault="True">
                확인
            </Button>
            <Button Name="cancelButton"
                Margin="10 0 0 0"
                Width="60"
                Height="30"
                IsCancel="True">
                취소
            </Button>
        </StackPanel>
    </Grid>
</PageFunction>

 

▶ MainPageFunction.xaml.cs

using System.Windows;
using System.Windows.Navigation;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지 함수
    /// </summary>
    public partial class MainPageFunction : PageFunction<string>
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainPageFunction(text)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="text">텍스트</param>
        public MainPageFunction(string text)
        {
            InitializeComponent();

            this.textBox.Text = text;

            this.okButton.Click     += okButton_Click;
            this.cancelButton.Click += cancelButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 확인 버튼 클릭시 처리하기 - okButton_Click(sender, e)

        /// <summary>
        /// 확인 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            OnReturn(new ReturnEventArgs<string>(this.textBox.Text));
        }

        #endregion
        #region 취소 버튼 클릭시 처리하기 - cancelButton_Click(sender, e)

        /// <summary>
        /// 취소 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            OnReturn(null);
        }

        #endregion
    }
}

 

▶ 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">
    <Grid>
        <StackPanel
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <TextBlock
                HorizontalAlignment="Center">
                <Hyperlink Name="hyperlink">페이지 함수 표시</Hyperlink>
            </TextBlock>
            <TextBlock Name="messageTextBlock"
                HorizontalAlignment="Center"
                Margin="0 10 0 0" />
        </StackPanel>
    </Grid>
</Page>

 

▶ MainPage.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지
    /// </summary>
    public partial class MainPage : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainPage()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainPage()
        {
            InitializeComponent();

            this.hyperlink.Click += hyperlink_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 하이퍼링크 클릭시 처리하기 - hyperlink_Click(sender, e)

        /// <summary>
        /// 하이퍼링크 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void hyperlink_Click(object sender, RoutedEventArgs e)
        {
            MainPageFunction pageFunction = new MainPageFunction("테스트");

            pageFunction.Return += pageFunction_Return;

            NavigationService.Navigate(pageFunction);
        }

        #endregion
        #region 페이지 함수 반환시 처리하기 - pageFunction_Return(sender, e)

        /// <summary>
        /// 페이지 함수 반환시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void pageFunction_Return(object sender, ReturnEventArgs<string> e)
        {
            if(string.IsNullOrWhiteSpace(e.Result))
            {
                this.messageTextBlock.Text = "(결과 없음)";
            }
            else
            {
                this.messageTextBlock.Text = $"[{DateTime.Now.ToString("HH:mm:ss")}] {e.Result}";
            }
        }

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

댓글을 달아 주세요