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

■ ListBox 클래스 : ItemsPanel 속성을 사용해 색상 휠 만들기

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

using System;

using System.Reflection;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Media;

using System.Windows.Shapes;

 

/// <summary>

/// 색상 휠

/// </summary>

public class ColorWheel : ListBox

{

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

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

 

    #region 생성자 - ColorWheel()

 

    /// <summary>

    /// 생성자

    /// </summary>

    public ColorWheel()

    {

        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 , 4.0 );

        rectangleFrameworkElementFactory.SetValue(Rectangle.HeightProperty, 12.0);

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

 

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

 

        dataTemplate.VisualTree = rectangleFrameworkElementFactory;

 

 

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

 

        foreach(PropertyInfo propertyInfo in propertyInfoArray)

        {

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

        }

    }

 

    #endregion

}

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

※ RadialPanel : "Panel 클래스 : RadialPanel 클래스 만들기" 참조

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요