728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 20면체(Icosahedron) 사용하기 (0) | 2018.12.31 |
---|---|
[C#/WPF] 팔면체(Octahedron) 사용하기 (0) | 2018.12.31 |
[C#/WPF] 정육면체(Cube) 사용하기 (0) | 2018.12.31 |
[C#/WPF] 사면체(Tetrahedron) 사용하기 (0) | 2018.12.31 |
[C#/WPF] 설치 폰트 샘플 표시하기 (0) | 2018.12.30 |
[C#/WPF] FrameworkElement 클래스 : 이미지 저장하기 (0) | 2018.12.30 |
[C#/WPF] 외곽선 경로 구하기 (0) | 2018.12.30 |
[C#/WPF] 대칭 복합 선 그리기 (0) | 2018.12.30 |
[C#/WPF] WriteableBitmap 클래스 : 비트맵 픽셀 설정하기 (0) | 2018.12.29 |
[C#/WPF] RenderTargetBitmap 클래스 : 텍스트 그리기 (0) | 2018.12.27 |
댓글을 달아 주세요