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

■ ListBox 클래스 : 색상 휠 박스 만들기

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


TestProject.zip


ColorWheelBox.cs

 

 

using System.Reflection;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Media;

using System.Windows.Shapes;

 

namespace TestProject

{

    /// <summary>

    /// 색상 휠 박스

    /// </summary>

    public class ColorWheelBox : ListBox

    {

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

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

 

        #region 생성자 - ColorWheelBox()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public ColorWheelBox()

        {

            FrameworkElementFactory radialPanelFrameworkElementFactory = new FrameworkElementFactory(typeof(RadialPanel));

 

            ItemsPanel = new ItemsPanelTemplate(radialPanelFrameworkElementFactory);

 

 

            DataTemplate dataTemplate = new DataTemplate(typeof(Brush));

 

            ItemTemplate = dataTemplate;

 

 

            FrameworkElementFactory rectangleFrameworkElementFactory = new FrameworkElementFactory(typeof(Rectangle));

 

            rectangleFrameworkElementFactory.SetValue(Rectangle.WidthProperty , 4d                           );

            rectangleFrameworkElementFactory.SetValue(Rectangle.HeightProperty, 12d                          );

            rectangleFrameworkElementFactory.SetValue(Rectangle.MarginProperty, new Thickness(1d, 8d, 1d, 8d));

 

            rectangleFrameworkElementFactory.SetBinding(Rectangle.FillProperty, new Binding(""));

 

            dataTemplate.VisualTree = rectangleFrameworkElementFactory;

 

 

            PropertyInfo[] propertyInfoArray = typeof(Brushes).GetProperties();

 

            foreach(PropertyInfo pPropertyInfo in propertyInfoArray)

            {

                Items.Add((Brush)pPropertyInfo.GetValue(null, null));

            }

        }

 

        #endregion

    }

}

 

 

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()

        {

            Title         = "ListBox 클래스 : 색상 휠 박스 만들기";

            SizeToContent = SizeToContent.WidthAndHeight;

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

            FontSize      = 16;

 

 

            ColorWheelBox colorWheelBox = new ColorWheelBox();

 

            colorWheelBox.Margin              = new Thickness(5);

            colorWheelBox.HorizontalAlignment = HorizontalAlignment.Center;

            colorWheelBox.VerticalAlignment   = VerticalAlignment.Center;

 

            Content = colorWheelBox;

 

            colorWheelBox.SetBinding(ColorWheelBox.SelectedValueProperty, "Background");

 

            colorWheelBox.DataContext = this;

        }

 

        #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

댓글을 달아 주세요