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

■ Menu 클래스 : 색상 그리드 박스 메뉴에서 색상 선택하기

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


TestProject.zip


MainWindow.cs

 

 

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Media;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            Width      = 800;

            Height     = 600;

            Title      = "Menu 클래스 : 색상 그리드 박스 메뉴에서 색상 선택하기";

            FontFamily = new FontFamily("나눔고딕코딩");

            FontSize   = 16;

 

            DockPanel dockPanel = new DockPanel();

 

            Content = dockPanel;

 

            Menu menu = new Menu();

 

            dockPanel.Children.Add(menu);

 

            DockPanel.SetDock(menu, Dock.Top);

 

            TextBlock textBlock = new TextBlock();

 

            textBlock.Text          = "색상 선택하기";

            textBlock.FontSize      = 32;

            textBlock.TextAlignment = TextAlignment.Center;

 

            dockPanel.Children.Add(textBlock);

 

            #region Color 메뉴

 

            MenuItem colorMenuItem = new MenuItem();

 

            colorMenuItem.Header = "_Color";

 

            menu.Items.Add(colorMenuItem);

 

            #endregion

                #region Foreground 메뉴

 

                MenuItem foregroundMenuItem = new MenuItem();

 

                foregroundMenuItem.Header = "_Foreground";

 

                colorMenuItem.Items.Add(foregroundMenuItem);

 

                ColorGridBox foregroundColorGridBox = new ColorGridBox();

 

                foregroundColorGridBox.SetBinding(ColorGridBox.SelectedValueProperty, "Foreground");

 

                foregroundColorGridBox.DataContext = this;

 

                foregroundMenuItem.Items.Add(foregroundColorGridBox);

 

                #endregion

                #region Background 메뉴

 

                MenuItem backgroundMenuItem = new MenuItem();

 

                backgroundMenuItem.Header = "_Background";

 

                colorMenuItem.Items.Add(backgroundMenuItem);

 

                ColorGridBox backgroundColorGridBox = new ColorGridBox();

 

                backgroundColorGridBox.SetBinding(ColorGridBox.SelectedValueProperty, "Background");

 

                backgroundColorGridBox.DataContext = this;

 

                backgroundMenuItem.Items.Add(backgroundColorGridBox);

 

                #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Public

 

        #region 프로그램 시작하기 - Main()

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        [STAThread]

        public static void Main()

        {

            Application application = new Application();

 

            application.Run(new MainWindow());

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요