[C#/WINUI3/.NET8] WinUI 3의 generic.xaml 파일에서 색상 구하기
■ WinUI 3의 generic.xaml 파일에서 색상을 구하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를 None으로
■ WinUI 3의 generic.xaml 파일에서 색상을 구하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를 None으로
■ ColorHelper 클래스의 ToHsv 확장 메소드를 사용해 Color 객체에서 HsvColor 객체를 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 |
using Microsoft.UI; using CommunityToolkit.WinUI; using CommunityToolkit.WinUI.Helpers; HsvColor hsvColor = Colors.Red.ToHsv(); |
※ CommunityToolkit.WinUI.Helpers 누겟을
■ ColorHelper 클래스의 ToHsl 확장 메소드를 사용해 Color 객체에서 HslColor 객체를 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 |
using Microsoft.UI; using CommunityToolkit.WinUI; using CommunityToolkit.WinUI.Helpers; HslColor hslColor = Colors.Red.ToHsl(); |
※ CommunityToolkit.WinUI.Helpers 누겟을
■ ColorHelper 클래스의 ToHex 확장 메소드를 사용해 색상에서 16진수 색상 문자열을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using Microsoft.UI; using CommunityToolkit.WinUI; string hexadecimalColorString = Colors.Red.ToHex(); |
※ CommunityToolkit.WinUI.Helpers 누겟을
■ ColorHelper 클래스의 ToColor 확장 메소드를 사용해 문자열에서 Color 객체를 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 |
using Windows.UI; using CommunityToolkit.WinUI.Helpers; Color color1 = "#ffff0000".ToColor(); Color color2 = "Red".ToColor(); |
※ CommunityToolkit.WinUI.Helpers 누겟을 설치했다.
■ color_picker 함수를 사용해 색상을 선택하는 방법을 보여준다. ▶ main.py
1 2 3 4 5 |
import streamlit as st color = st.color_picker("색상", "#ff0000") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ hex 함수를 사용해 RGBA 색상값을 ARGB 색상 16진수 문자열 값으로 구하는 방법을 보여준다. ▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
red = 166 green = 128 blue = 255 alpha = 0.8 redHexadecimalString = hex(red ).replace("0x", "") greenHexadecimalString = hex(green).replace("0x", "") blueHexadecimalString = hex(blue ).replace("0x", "") alphaHexadecimalString = hex(int(round(alpha * 255, 0))).replace("0x", "") print(redHexadecimalString ) # a6 print(greenHexadecimalString) # 80 print(blueHexadecimalString ) # ff print(alphaHexadecimalString) # cc argbHexadecimalString = "#{alphaHexadecimalString}{redHexadecimalString}{greenHexadecimalString}{blueHexadecimalString}".format( alphaHexadecimalString = str(alphaHexadecimalString).ljust(2, "0"), redHexadecimalString = str(redHexadecimalString ).ljust(2, "0"), greenHexadecimalString = str(greenHexadecimalString).ljust(2, "0"), blueHexadecimalString = str(blueHexadecimalString ).ljust(2, "0") ) print(argbHexadecimalString) # #cca680ff |
■ hex 함수를 사용해 ARGB 색상의 16진수 문자열 값을 구하는 방법을 보여준다. ▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
alphaValue = 0.8 redValue = 166 greenValue = 128 blueValue = 255 alphaHexadecimalValue = hex(int(round(alphaValue * 255, 0))).replace("0x", "") redHexadecimalValue = hex(redValue ).replace("0x", "") greenHexadecimalValue = hex(greenValue).replace("0x", "") blueHexadecimalValue = hex(blueValue ).replace("0x", "") print(f"#{alphaHexadecimalValue}{redHexadecimalValue}{greenHexadecimalValue}{blueHexadecimalValue}") # #cca680ff |
■ hex 함수를 사용해 RGB 색상의 16진수 문자열 값을 구하는 방법을 보여준다. ▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 |
redValue = 166 greenValue = 128 blueValue = 255 redHexadecimalValue = hex(redValue ).replace("0x", "") greenHexadecimalValue = hex(greenValue).replace("0x", "") blueHexadecimalValue = hex(blueValue ).replace("0x", "") print(f"#{redHexadecimalValue}{greenHexadecimalValue}{blueHexadecimalValue}") # #a680ff |
■ HSV 색상 선택기를 만드는 방법을 보여준다. ▶ Point2D.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
namespace TestProject; /// <summary> /// 2D 포인트 /// </summary> public class Point2D { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region X 좌표 - X /// <summary> /// X 좌표 /// </summary> public double X { get; set; } #endregion #region Y 좌표 - Y /// <summary> /// Y 좌표 /// </summary> public double Y { get; set; } #endregion } |
▶ ColorPicker.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
using System.Drawing.Imaging; namespace TestProject; /// <summary> /// 색상 선택기 /// </summary> public class ColorPicker { //////////////////////////////////////////////////////////////////////////////////////////////////// Enumeration ////////////////////////////////////////////////////////////////////////////////////////// Public #region 영역 - Area /// <summary> /// 영역 /// </summary> public enum Area { /// <summary> /// 외부 /// </summary> Outside, /// <summary> /// 휠 /// </summary> Wheel, /// <summary> /// 삼각형 /// </summary> Triangle } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Structure ////////////////////////////////////////////////////////////////////////////////////////// Public #region 선택 결과 - PickResult /// <summary> /// 선택 결과 /// </summary> public struct PickResult { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 영역 - Area /// <summary> /// 영역 /// </summary> public Area Area { get; set; } #endregion #region 색상 - Hue /// <summary> /// 색상 /// </summary> public double? Hue { get; set; } #endregion #region 채도 - Saturation /// <summary> /// 채도 /// </summary> public double? Saturation { get; set; } #endregion #region 값 - Value /// <summary> /// 값 /// </summary> public double? Value { get; set; } #endregion } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 크기 - Size /// <summary> /// 크기 /// </summary> public int Size { get; } #endregion #region 중앙 X - CenterX /// <summary> /// 중앙 X /// </summary> public int CenterX => Size / 2; #endregion #region 중앙 Y - CenterY /// <summary> /// 중앙 Y /// </summary> public int CenterY => Size / 2; #endregion #region 내부 반경 - InnerRadius /// <summary> /// 내부 반경 /// </summary> public int InnerRadius => Size * 5 / 12; #endregion #region 외부 반경 - OuterRadius /// <summary> /// 외부 반경 /// </summary> public int OuterRadius => Size / 2; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ColorPicker(size) /// <summary> /// 생성자 /// </summary> /// <param name="size">크기</param> public ColorPicker(int size = 400) { Size = size; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이미지 그리기 - DrawImage(hue, saturation, value) /// <summary> /// 이미지 그리기 /// </summary> /// <param name="hue">색상</param> /// <param name="saturation">채도</param> /// <param name="value">값</param> /// <returns>이미지</returns> public Image DrawImage(double hue = 0d, double saturation = 1d, double value = 1d) { Bitmap bitmap = new Bitmap(Size, Size, PixelFormat.Format32bppArgb); for(int y = 0; y < Size; y++) { for(int x = 0; x < Size; x++) { Color color; PickResult pickResult = Pick(x, y); if(pickResult.Area == Area.Outside) { color = Color.Transparent; } else if(pickResult.Area == Area.Wheel) { color = GetHSVColor(pickResult.Hue.Value, saturation, value, 1); } else { color = GetHSVColor(hue, pickResult.Saturation.Value, pickResult.Value.Value, 1); } bitmap.SetPixel(x, y, color); } } return bitmap; } #endregion #region 휠 위치 구하기 - GetWheelPosition(hue) /// <summary> /// 휠 위치 구하기 /// </summary> /// <param name="hue">색상</param> /// <returns>휠 위치</returns> public Point2D GetWheelPosition(double hue) { double middleRadius = (InnerRadius + OuterRadius) / 2; return new Point2D { X = CenterX + middleRadius * Math.Sin(hue), Y = CenterY - middleRadius * Math.Cos(hue) }; } #endregion #region 삼각형 위치 구하기 - GetTrianglePosition(saturation, value) /// <summary> /// 삼각형 위치 구하기 /// </summary> /// <param name="saturation">채도</param> /// <param name="value">값</param> /// <returns>삼각형 위치</returns> public Point2D GetTrianglePosition(double saturation, double value) { double squareRoot3 = Math.Sqrt(3); return new Point2D { X = CenterX + InnerRadius * (2 * value - saturation * value - 1) * squareRoot3 / 2, Y = CenterY + InnerRadius * (1 - 3 * saturation * value) / 2 }; } #endregion #region 선택하기 - Pick(x, y) /// <summary> /// 선택하기 /// </summary> /// <param name="x">X 좌표</param> /// <param name="y">Y 좌표</param> /// <returns>선택 결과</returns> public PickResult Pick(double x, double y) { double distanceFromCenter = Math.Sqrt((x - CenterX) * (x - CenterX) + (y - CenterY) * (y - CenterY)); double squareRoot3 = Math.Sqrt(3); if(distanceFromCenter > OuterRadius) { return new PickResult { Area = Area.Outside }; } else if(distanceFromCenter > InnerRadius) { double angle = Math.Atan2(y - CenterY, x - CenterX) + Math.PI / 2; if(angle < 0) { angle += 2 * Math.PI; } double hue = angle; return new PickResult { Area = Area.Wheel, Hue = hue }; } else { double x1 = (x - CenterX) * 1.0d / InnerRadius; double y1 = (y - CenterY) * 1.0d / InnerRadius; if(0 * x1 + 2 * y1 > 1) { return new PickResult { Area = Area.Outside }; } else if(squareRoot3 * x1 + (-1) * y1 > 1) { return new PickResult { Area = Area.Outside }; } else if(-squareRoot3 * x1 + (-1) * y1 > 1) { return new PickResult { Area = Area.Outside }; } else { double saturation = (1 - 2 * y1) / (squareRoot3 * x1 - y1 + 2); double value = (squareRoot3 * x1 - y1 + 2) / 3; return new PickResult { Area = Area.Triangle, Saturation = saturation, Value = value }; } } } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region RGB 색상 구하기 - GetRGBColor(red, green, blue, alpha) /// <summary> /// RGB 색상 구하기 /// </summary> /// <param name="red">적색</param> /// <param name="green">녹색</param> /// <param name="blue">청색</param> /// <param name="alpha">투명도</param> /// <returns>RGB 색상</returns> private Color GetRGBColor(double red, double green, double blue, double alpha) { return Color.FromArgb ( Math.Min(255, (int)(alpha * 256)), Math.Min(255, (int)(red * 256)), Math.Min(255, (int)(green * 256)), Math.Min(255, (int)(blue * 256)) ); } #endregion #region HSV 색상 구하기 - GetHSVColor(hue, saturation, value, alpha) /// <summary> /// HSV 색상 구하기 /// </summary> /// <param name="hue">색상</param> /// <param name="saturation">채도</param> /// <param name="value">값</param> /// <param name="alpha">알파</param> /// <returns>색상</returns> private Color GetHSVColor(double hue, double saturation, double value, double alpha) { double chroma = value * saturation; double step = Math.PI / 3; double interm = chroma * (1 - Math.Abs((hue / step) % 2.0 - 1)); double shift = value - chroma; if(hue < 1 * step) return GetRGBColor(shift + chroma, shift + interm, shift + 0 , alpha); if(hue < 2 * step) return GetRGBColor(shift + interm, shift + chroma, shift + 0 , alpha); if(hue < 3 * step) return GetRGBColor(shift + 0 , shift + chroma, shift + interm, alpha); if(hue < 4 * step) return GetRGBColor(shift + 0 , shift + interm, shift + chroma, alpha); if(hue < 5 * step) return GetRGBColor(shift + interm, shift + 0 , shift + chroma, alpha); return GetRGBColor(shift + chroma, shift + 0, shift + interm, alpha); } #endregion } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); double hue = 3.3d; double saturation = 0.4d; double value = 0.9d; ColorPicker colorPicker = new ColorPicker(400); Image colorPickerImage = colorPicker.DrawImage(hue, saturation, value); using(Graphics imageGraphics = Graphics.FromImage(colorPickerImage)) { Pen pen = value < 0.5d ? Pens.White : Pens.Black; Point2D wheelPoint = colorPicker.GetWheelPosition(hue); imageGraphics.DrawEllipse(pen, (float)wheelPoint.X - 5, (float)wheelPoint.Y - 5, 10, 10); Point2D trianglePoint = colorPicker.GetTrianglePosition(saturation, value); imageGraphics.DrawEllipse(pen, (float)trianglePoint.X - 5, (float)trianglePoint.Y - 5, 10, 10); } this.pictureBox.Image = colorPickerImage; } #endregion } } |
TestProject.zip
■ SystemColors 클래스를 사용해 시스템 브러시를 사용하는 방법을 보여준다. ▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<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="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <Style TargetType="{x:Type TextBlock}"> <Setter Property="Margin" Value="10 20 10 0"/> </Style> <Style TargetType="{x:Type Rectangle}"> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="Margin" Value="10 5 10 0" /> <Setter Property="Width" Value="120" /> <Setter Property="Height" Value="20" /> <Setter Property="StrokeThickness" Value="1" /> <Setter Property="Stroke" Value="Black" /> </Style> <Style TargetType="{x:Type Button}"> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="Margin" Value="10 5 10 0" /> </Style> </Window.Resources> <ScrollViewer> <Grid Margin="10"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="5" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <StackPanel Name="systemBrushesPanel" Grid.Row="0" Grid.Column="0" Background="White" /> <Rectangle Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="Black" RadiusX="10" RadiusY="10" /> <StackPanel Name="gradientExampleStackPanel" Grid.Row="0" Grid.Column="2" Background="White" /> </Grid> </ScrollViewer> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); AddSystemBrushesPanelChildren(); AddGradientExamplesStackPanelChildren(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 시스템 브러시 패널 자식들 추가하기 - AddSystemBrushesPanelChildren() /// <summary> /// 시스템 브러시 패널 자식들 추가하기 /// </summary> private void AddSystemBrushesPanelChildren() { TextBlock textBlock = new TextBlock { Text = "ActiveBorder" }; Rectangle rectangle = new Rectangle { Fill = SystemColors.ActiveBorderBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ActiveCaption" }; rectangle = new Rectangle { Fill = SystemColors.ActiveCaptionBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ActiveCaptionText" }; rectangle = new Rectangle { Fill = SystemColors.ActiveCaptionTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "AppWorkspace" }; rectangle = new Rectangle { Fill = SystemColors.AppWorkspaceBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "Control" }; rectangle = new Rectangle { Fill = SystemColors.ControlBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ControlDark" }; rectangle = new Rectangle { Fill = SystemColors.ControlDarkBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ControlDarkDark" }; rectangle = new Rectangle { Fill = SystemColors.ControlDarkDarkBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ControlLight" }; rectangle = new Rectangle { Fill = SystemColors.ControlLightBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ControlLightLight" }; rectangle = new Rectangle { Fill = SystemColors.ControlLightLightBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ControlText" }; rectangle = new Rectangle { Fill = SystemColors.ControlTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "Desktop"}; rectangle = new Rectangle(); rectangle.SetResourceReference(Shape.FillProperty, SystemColors.DesktopBrushKey); this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "GradientActiveCaption" }; rectangle = new Rectangle { Fill = SystemColors.GradientActiveCaptionBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "GradientInactiveCaption" }; rectangle = new Rectangle { Fill = SystemColors.GradientInactiveCaptionBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "GrayText" }; rectangle = new Rectangle { Fill = SystemColors.GrayTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "Highlight" }; rectangle = new Rectangle { Fill = SystemColors.HighlightBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "HighlightText" }; rectangle = new Rectangle { Fill = SystemColors.HighlightTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "HotTrack"}; rectangle = new Rectangle { Fill = SystemColors.HotTrackBrush}; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "InactiveBorder" }; rectangle = new Rectangle { Fill = SystemColors.InactiveBorderBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "InactiveCaption" }; rectangle = new Rectangle { Fill = SystemColors.InactiveCaptionBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "InactiveCaptionText" }; rectangle = new Rectangle { Fill = SystemColors.InactiveCaptionTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "Info" }; rectangle = new Rectangle { Fill = SystemColors.InfoBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "InfoText" }; rectangle = new Rectangle { Fill = SystemColors.InfoTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "Menu" }; rectangle = new Rectangle { Fill = SystemColors.MenuBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "MenuBar" }; rectangle = new Rectangle { Fill = SystemColors.MenuBarBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "MenuHighlight" }; rectangle = new Rectangle { Fill = SystemColors.MenuHighlightBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "MenuText" }; rectangle = new Rectangle { Fill = SystemColors.MenuTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ScrollBar" }; rectangle = new Rectangle { Fill = SystemColors.ScrollBarBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "Window" }; rectangle = new Rectangle { Fill = SystemColors.WindowBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(rectangle); Button button; textBlock = new TextBlock { Text = "WindowFrame" }; button = new Button { Width = 120, Height = 20, Background = SystemColors.WindowFrameBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(button ); textBlock = new TextBlock { Text = "WindowText" }; button = new Button { Width = 120, Height = 20, Background = SystemColors.WindowTextBrush }; this.systemBrushesPanel.Children.Add(textBlock); this.systemBrushesPanel.Children.Add(button); } #endregion #region 그라디언트 예제 스택 패널 자식들 추가하기 - AddGradientExamplesStackPanelChildren() /// <summary> /// 그라디언트 예제 스택 패널 자식들 추가하기 /// </summary> public void AddGradientExamplesStackPanelChildren() { TextBlock textBlock = new TextBlock { Text = "System Color Gradient Examples", HorizontalAlignment = HorizontalAlignment.Left, FontWeight = FontWeights.Bold }; this.gradientExampleStackPanel.Children.Add(textBlock); Rectangle rectangle; textBlock = new TextBlock { Text = "ControlDark to ControlLight" }; rectangle = new Rectangle { Fill = new RadialGradientBrush(SystemColors.ControlDarkColor, SystemColors.ControlLightColor) }; this.gradientExampleStackPanel.Children.Add(textBlock); this.gradientExampleStackPanel.Children.Add(rectangle); textBlock = new TextBlock { Text = "ControlDarkDark to ControlLightLight" }; rectangle = new Rectangle { Fill = new LinearGradientBrush(SystemColors.ControlDarkDarkColor, SystemColors.ControlLightLightColor, 45) }; this.gradientExampleStackPanel.Children.Add(textBlock); this.gradientExampleStackPanel.Children.Add(rectangle); Button button; textBlock = new TextBlock { Text = "Desktop to AppWorkspace" }; button = new Button { Width = 120, Height = 20, Background = new RadialGradientBrush(SystemColors.DesktopColor, SystemColors.AppWorkspaceColor) }; this.gradientExampleStackPanel.Children.Add(textBlock); this.gradientExampleStackPanel.Children.Add(button ); textBlock = new TextBlock { Text = "Desktop to Control" }; button = new Button { Width = 120, Height = 20, Background = new RadialGradientBrush(SystemColors.DesktopColor, SystemColors.ControlColor) }; this.gradientExampleStackPanel.Children.Add(textBlock); this.gradientExampleStackPanel.Children.Add(button ); } #endregion } } |
TestProject.zip
■ ColorTranslator 클래스의 ToHtml 정적 메소드를 사용해 16진수 색상 코드를 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 |
using System.Drawing; string colorCode = ColorTranslator.ToHtml(Color.FromArgb(255, 0, 0)); |
■ ColorConverter 클래스의 ConvertFromString 정적 메소드를 사용해 16진수 색상 코드에서 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 |
using System.Windows.Media; Color color = (Color)ColorConverter.ConvertFromString("#ffdfd991"); |
■ ColorConversionExtensions 클래스의 WithBlackKey 확장 메소드를 사용해 검정색 값을 설정한 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.White; Color targetColor = sourceColor.WithBlackKey(0.5); |
■ ColorConversionExtensions 클래스의 WithYellow 확장 메소드를 사용해 노란색 값을 설정한 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.White; Color targetColor = sourceColor.WithYellow(0.5); |
■ ColorConversionExtensions 클래스의 WithMagenta 확장 메소드를 사용해 자홍색 값을 설정한 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.White; Color targetColor = sourceColor.WithMagenta(0.5); |
■ ColorConversionExtensions 클래스의 WithCyan 확장 메소드를 사용해 청록색 값을 설정한 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.White; Color targetColor = sourceColor.WithCyan(0.5); |
■ ColorConversionExtensions 클래스의 WithGreen 확장 메소드를 사용해 녹색 값을 설정한 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.White; Color targetColor = sourceColor.WithGreen(255); |
■ ColorConversionExtensions 클래스의 WithBlue 확장 메소드를 사용해 청색 값을 설정한 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.White; Color targetColor = sourceColor.WithBlue(255); |
■ ColorConversionExtensions 클래스의 WithRed 확장 메소드를 사용해 적색 값을 설정한 색상을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.White; Color targetColor = sourceColor.WithRed(255); |
■ ColorConversionExtensions 클래스의 ToRgbString 확장 메소드를 사용해 RGB 문자열을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.Red; string rgb = sourceColor.ToRgbString(); |
■ ColorConversionExtensions 클래스의 ToHslString 확장 메소드를 사용해 HSL 문자열을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.Red; string hsl = sourceColor.ToHslString(); |
■ ColorConversionExtensions 클래스의 ToRgbaString 확장 메소드를 사용해 RGBA 문자열을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.Red; string rgba = sourceColor.ToRgbaString(); |
■ ColorConversionExtensions 클래스의 ToHslaString 확장 메소드를 사용해 HSLA 문자열을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.Red; string hsla = sourceColor.ToHslaString(); |
■ ColorConversionExtensions 클래스의 ToCmykString 확장 메소드를 사용해 CMYK 문자열을 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 |
using CommunityToolkit.Maui.Core.Extensions; Color sourceColor = Colors.Red; string cmyk = sourceColor.ToCmykString(); |