■ Menu 클래스를 사용해 색상 그리드 박스 메뉴에서 색상을 선택하는 방법을 보여준다.
▶ MainWindow.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 |
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { Width = 800; Height = 600; Title = "Menu 클래스 : 색상 그리드 박스 메뉴에서 색상 선택하기"; FontFamily = new FontFamily("나눔고딕코딩"); FontSize = 16; DockPanel dockPanel = new DockPanel(); Content = dockPanel; Menu menu = new Menu(); dockPanel.Children.Add(menu); DockPanel.SetDock(menu, Dock.Top); TextBlock textBlock = new TextBlock(); textBlock.Text = "색상 선택하기"; textBlock.FontSize = 32; textBlock.TextAlignment = TextAlignment.Center; dockPanel.Children.Add(textBlock); #region Color 메뉴 MenuItem colorMenuItem = new MenuItem(); colorMenuItem.Header = "_Color"; menu.Items.Add(colorMenuItem); #endregion #region Foreground 메뉴 MenuItem foregroundMenuItem = new MenuItem(); foregroundMenuItem.Header = "_Foreground"; colorMenuItem.Items.Add(foregroundMenuItem); ColorGridBox foregroundColorGridBox = new ColorGridBox(); foregroundColorGridBox.SetBinding(ColorGridBox.SelectedValueProperty, "Foreground"); foregroundColorGridBox.DataContext = this; foregroundMenuItem.Items.Add(foregroundColorGridBox); #endregion #region Background 메뉴 MenuItem backgroundMenuItem = new MenuItem(); backgroundMenuItem.Header = "_Background"; colorMenuItem.Items.Add(backgroundMenuItem); ColorGridBox backgroundColorGridBox = new ColorGridBox(); backgroundColorGridBox.SetBinding(ColorGridBox.SelectedValueProperty, "Background"); backgroundColorGridBox.DataContext = this; backgroundMenuItem.Items.Add(backgroundColorGridBox); #endregion } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> [STAThread] public static void Main() { Application application = new Application(); application.Run(new MainWindow()); } #endregion } } |