[MainPage.xaml]



<UserControl x:Class="RiaButton.MainPage"

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

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

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <StackPanel>

            <Button Content="버튼1" Click="Button_Click"></Button>

            <Button Content="버튼2" x:Name="btnTwo" Click="btnTwo_Click" ClickMode="Press" />

            <Button Content="버튼3" x:Name="btnThree" Click="btnThree_Click" ClickMode="Hover" />

            <Button Content="버튼4" x:Name="btnFour" Click="btnFour_Click" ClickMode="Release" />

           

            <!-- Click이벤트에 관한 코드부분을 코드비하인드페이지에서 순수xaml코드로 작성함. -->

            <Button Content="5" x:Name="btnFive"></Button>

        </StackPanel>

    </Grid>

</UserControl>

 

 





[MainPage.xaml.cs]


using System.Windows;

using System.Windows.Controls;

 

namespace RiaButton

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            // 생성자를 통해서 Click이벤트를 동적으로 부여

            this.btnFive.Click += new RoutedEventHandler(btnFive_Click);

        }

 

        void btnFive_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show("생성자를 통해서 Click이벤트 부여");

        }

 

        private void Button_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show("첫번째");

        }

 

        private void btnTwo_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show("두번째");

        }

 

        private void btnThree_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show("세번째");

        }

 

        private void btnFour_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show("네번째");

        }

    }

}

 

 





































Posted by holland14
: