첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="ComboBox 엘리먼트 : DropDownOpened/DropDownClosed 이벤트 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <StackPanel
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <Label Name="label" />
        <ComboBox Name="comboBox"
            Margin="10"
            Width="100"
            Height="25"
            StaysOpenOnEdit="true"
            IsEditable="true">
            <ComboBoxItem>항목01</ComboBoxItem>
            <ComboBoxItem>항목02</ComboBoxItem>
            <ComboBoxItem>항목03</ComboBoxItem>
            <ComboBoxItem>항목04</ComboBoxItem>
        </ComboBox>
    </StackPanel>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

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

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

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

            this.comboBox.DropDownOpened += comboBox_DropDownOpened;
            this.comboBox.DropDownClosed += comboBox_DropDownClosed;
        }

        #endregion

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

        #region 콤보 박스 DROP DOWN OPEN 처리하기 - comboBox_DropDownOpened(sender, e)

        /// <summary>
        /// 콤보 박스 DROP DOWN OPEN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void comboBox_DropDownOpened(object sender, EventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            if(comboBox.IsDropDownOpen == true)
            {
                this.label.Content = "DROP DOWN OPEN";
            }
        }

        #endregion
        #region 콤보 박스 DROP DOWN CLOSE 처리하기 - comboBox_DropDownClosed(sender, e)

        /// <summary>
        /// 콤보 박스 DROP DOWN CLOSE 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void comboBox_DropDownClosed(object sender, EventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            if(comboBox.IsDropDownOpen == false)
            {
                this.label.Content = "DROP DOWN CLOSE";
            }
        }

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

댓글을 달아 주세요