첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ ColorInfo.cs

using System.Windows.Media;

namespace TestProject
{
    /// <summary>
    /// 색상 정보
    /// </summary>
    public class ColorInfo
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 색상명 - ColorName

        /// <summary>
        /// 색상명
        /// </summary>
        public string ColorName { get; set; }

        #endregion
        #region 색상 - Color

        /// <summary>
        /// 색상
        /// </summary>
        public Color Color { get; set; }

        #endregion
        #region 샘플 브러시 - SampleBrush

        /// <summary>
        /// 샘플 브러시
        /// </summary>
        public SolidColorBrush SampleBrush
        {
            get
            {
                return new SolidColorBrush(Color);
            }
        }

        #endregion
        #region 16진수 값 - HexdecimalValue 

        /// <summary>
        /// 16진수 값
        /// </summary>
        public string HexdecimalValue
        {
            get
            {
                return Color.ToString();
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - ColorInfo(colorName, color)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="colorName">색상명</param>
        /// <param name="color">색상</param>
        public ColorInfo(string colorName, Color color)
        {
            ColorName = colorName;
            Color     = color;
        }

        #endregion
    }
}

 

728x90

 

▶ 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="600"
    Height="450"
    Title="색상 리스트 표시하기"
    Loaded="Window_Loaded">
    <Grid>
        <ListBox Name="listBox">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel.Resources>
                            <Style TargetType="TextBlock">
                                <Setter Property="Margin" Value="5 0 0 0" />
                            </Style>
                        </StackPanel.Resources>
                        <Rectangle Width="30" Fill="{Binding SampleBrush}" />
                        <TextBlock Width="130" Text="{Binding ColorName}" />
                        <TextBlock Width="70" Text="{Binding HexdecimalValue}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>

 

300x250

 

▶ MainWindow.xaml.cs

using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Media;

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

        #region 생성자 - MainWindow()

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

        #endregion

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

        #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)

        /// <summary>
        /// 윈도우 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var colorEnumerable = from PropertyInfo property in typeof(Colors).GetProperties()
                                  orderby property.Name
                                  select new ColorInfo
                                  (
                                      property.Name,
                                      (Color)property.GetValue(null, null)
                                  );

            this.listBox.ItemsSource = colorEnumerable;
        }

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

댓글을 달아 주세요