첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

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
    }
}

 

728x90

 

▶ 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 클래스 : ItemsPanel 속성을 사용해 색상 휠 박스 만들기";
            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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요