728x90
반응형
728x170
■ SystemColors 클래스를 사용해 시스템 색상을 표시하는 방법을 보여준다.
▶ SystemColorItem.cs
using System.Windows.Media;
namespace TestProject
{
/// <summary>
/// 시스템 색상 항목
/// </summary>
public class SystemColorItem
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 명칭 - Name
/// <summary>
/// 명칭
/// </summary>
public string Name { get; set; }
#endregion
#region 색성 - Color
/// <summary>
/// 색상
/// </summary>
public Color Color { get; set; }
#endregion
#region 반전 색상 - InvertColor
/// <summary>
/// 반전 색상
/// </summary>
public Color InvertColor
{
get
{
return Color.FromArgb(0xff, (byte)(255 - Color.R), (byte)(255 - Color.G), (byte)(255 - Color.B));
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 문자열 구하기 - ToString()
/// <summary>
/// 문자열 구하기
/// </summary>
/// <returns>문자열</returns>
public override string ToString()
{
return Name;
}
#endregion
}
}
▶ 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="800"
Height="600"
Title="SystemColors 클래스를 사용해 시스템 색상 표시하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<ScrollViewer>
<WrapPanel Name="wrapPanel"
Background="{StaticResource {x:Static SystemColors.ActiveBorderBrushKey}}"
ItemWidth="200"
ItemHeight="100" />
</ScrollViewer>
</Grid>
</Window>
▶ MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 시스템 색상 아이템 리스트
/// </summary>
private List<SystemColorItem> systemColorItemList = new List<SystemColorItem>();
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 시스템 색상 아이템 리스트 - SystemColorItemList
/// <summary>
/// 시스템 색상 아이템 리스트
/// </summary>
public List<SystemColorItem> SystemColorItemList
{
get
{
return this.systemColorItemList;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
Loaded += Window_Loaded;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)
/// <summary>
/// 윈도우 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SetSystemColorItemList();
AddWrapPanelData();
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 시스템 색상 아이템 리스트 설정하기 - SetSystemColorItemList()
/// <summary>
/// 시스템 색상 아이템 리스트 설정하기
/// </summary>
private void SetSystemColorItemList()
{
this.systemColorItemList.Clear();
Type type = typeof(SystemColors);
PropertyInfo[] propertyInfoArray = type.GetProperties(BindingFlags.Public | BindingFlags.Static);
for(int i = 0; i < propertyInfoArray.Length; i++)
{
SystemColorItem item = new SystemColorItem();
object propertyValue = propertyInfoArray[i].GetValue(null, null);
string typeName = propertyValue.GetType().FullName;
string name = propertyInfoArray[i].Name;
if(typeName == typeof(Color).FullName)
{
item.Color = (Color)propertyValue;
item.Name = name;
this.systemColorItemList.Add(item);
}
}
}
#endregion
#region 랩 패널 데이터 추가하기 - AddWrapPanelData()
/// <summary>
/// 랩 패널 데이터 추가하기
/// </summary>
private void AddWrapPanelData()
{
foreach(SystemColorItem item in this.systemColorItemList)
{
TextBlock textBlock = new TextBlock();
textBlock.Background = new SolidColorBrush(item.Color );
textBlock.Foreground = new SolidColorBrush(item.InvertColor);
textBlock.Text = item.Name;
this.wrapPanel.Children.Add(textBlock);
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] TreeView 클래스 : 데이터 바인딩시 부모 노드 사전 설정하기 (0) | 2019.06.02 |
---|---|
[C#/WPF] TreeView 클래스 : ItemContainerGenerator 속성을 사용해 바인딩 데이터의 트리 노드 구하기 (0) | 2019.06.02 |
[C#/WPF] ComponentDispatcher 클래스 : ThreadFilterMessage 정적 이벤트를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
[C#/WPF] HwndSource 클래스 : AddHook 메소드를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
[C#/WPF] Dispatcher 클래스 : UnhandledExceptionFilter/UnhandledException 이벤트를 사용해 비정상 종료 방지하기 (0) | 2019.06.02 |
[C#/WPF] 메모리 손실이 없는 비트맵 소스 구하기 (0) | 2019.05.30 |
[C#/WPF] AppDomain 클래스 : 동일 프로세스에서 멀티 WPF 애플리케이션 실행하기 (0) | 2019.05.30 |
[C#/WPF] 복수 UI 스레드 윈도우 사용하기 (0) | 2019.05.30 |
[C#/WPF] ScrollViewer 클래스 : 마우스를 사용해 스크롤하기 (0) | 2019.05.28 |
[C#/WPF] BitmapImage 클래스 : 웹에서 비트맵 이미지 구하기 (0) | 2019.05.27 |
댓글을 달아 주세요