■ BarManager 클래스에서 공통 컨테이너에 Bar를 생성하는 방법을 보여준다.
▶ 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 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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" xmlns:local="clr-namespace:TestProject" UseLayoutRounding="True" Width="800" Height="600" dx:ThemeManager.ThemeName="Office2013" Title="BarManager 클래스 : 공통 컨테이너에 Bar 생성하기" FontFamily="나눔고딕코딩" FontSize="16" DataContext="{dxmvvm:ViewModelSource Type=local:MainViewModel}"> <Grid> <dxb:BarManager ToolbarGlyphSize="Small"> <dxb:BarManager.Bars> <dxb:Bar Caption="File" IsMainMenu="True"> <dxb:BarSubItem Name="fileItem" Content="File"> <dxb:BarButtonItem Name="openItem" Glyph="{dx:DXImage Image=Open_16x16.png}" LargeGlyph="{dx:DXImage Image=Open_32x32.png}" Command="{Binding OpenFileCommand}" Content="Open" /> <dxb:BarButtonItem Name="newItem" Glyph="{dx:DXImage Image=New_16x16.png}" LargeGlyph="{dx:DXImage Image=New_32x32.png}" Command="{Binding NewFileCommand}" Content="New" /> </dxb:BarSubItem> <dxb:BarSubItem Name="editItem" Content="Edit"> <dxb:BarButtonItemLink BarItemName="cutItem" /> <dxb:BarButtonItemLink BarItemName="copyItem" /> <dxb:BarButtonItemLink BarItemName="pasteItem" /> </dxb:BarSubItem> </dxb:Bar> <dxb:Bar Caption="Edit"> <dxb:BarButtonItem Name="cutItem" Glyph="{dx:DXImage Image=Cut_16x16.png}" LargeGlyph="{dx:DXImage Image=Cut_32x32.png}" Command="Cut" Content="Cut" /> <dxb:BarButtonItem Name="copyItem" Glyph="{dx:DXImage Image=Copy_16x16.png}" LargeGlyph="{dx:DXImage Image=Copy_32x32.png}" Command="Copy" Content="Copy" /> <dxb:BarButtonItem Name="pasteItem" Glyph="{dx:DXImage Image=Paste_16x16.png}" LargeGlyph="{dx:DXImage Image=Paste_32x32.png}" Command="Paste" Content="Paste" /> <dxb:BarItemSeparator/> <dxb:BarCheckItem Name="boldItem" Glyph="{dx:DXImage Image=Bold_16x16.png}" LargeGlyph="{dx:DXImage Image=Bold_32x32.png}" IsChecked="{Binding IsBold, Mode=TwoWay}" Content="Bold" /> <dxb:BarCheckItem Name="italicItem" Glyph="{dx:DXImage Image=Italic_16x16.png}" LargeGlyph="{dx:DXImage Image=Italic_32x32.png}" IsChecked="{Binding IsItalic, Mode=TwoWay}" Content="Italic" /> <dxb:BarCheckItem Name="biUnderline" Glyph="{dx:DXImage Image=Underline_16x16.png}" LargeGlyph="{dx:DXImage Image=Underline_32x32.png}" IsChecked="{Binding IsUnderline, Mode=TwoWay}" Content="Underline" /> </dxb:Bar> <dxb:Bar IsStatusBar="True" ShowSizeGrip="True"> <dxb:Bar.DockInfo> <dxb:BarDockInfo ContainerType="Bottom" /> </dxb:Bar.DockInfo> <dxb:BarStaticItem Name="rowItem" ShowBorder="False" Content="Row :" /> <dxb:BarStaticItem Name="rowValueItem" ShowBorder="False" Content="1" /> <dxb:BarCheckItem Name="leftItem" Alignment="Far" GroupIndex="1" IsChecked="True" Glyph="{dx:DXImage Image=AlignLeft_16x16.png}" Command="{Binding SetAlignmentCommand}" CommandParameter="{x:Static TextAlignment.Left}" /> <dxb:BarCheckItem Name="centerItem" Alignment="Far" GroupIndex="1" Glyph="{dx:DXImage Image=AlignCenter_16x16.png}" Command="{Binding SetAlignmentCommand}" CommandParameter="{x:Static TextAlignment.Center}" /> <dxb:BarCheckItem Name="rightItem" Alignment="Far" GroupIndex="1" Glyph="{dx:DXImage Image=AlignRight_16x16.png}" Command="{Binding SetAlignmentCommand}" CommandParameter="{x:Static TextAlignment.Right}" /> </dxb:Bar> </dxb:BarManager.Bars> <TextBox TextAlignment="{Binding TextAlignment}" TextDecorations="{Binding TextDecorations}" FontWeight="{Binding FontWeight}" FontStyle="{Binding FontStyle}" Text="{Binding Text, Mode=TwoWay}" /> </dxb:BarManager> </Grid> </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 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion } } |
▶ MainViewModel.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 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 뷰 모델 /// </summary> public class MainViewModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 볼드체 여부 - IsBold /// <summary> /// 볼드체 여부 /// </summary> public virtual bool IsBold { get; set; } #endregion #region 이탤릭체 여부 - IsItalic /// <summary> /// 이탤릭체 여부 /// </summary> public virtual bool IsItalic { get; set; } #endregion #region 밑줄 여부 - IsUnderline /// <summary> /// 밑줄 여부 /// </summary> public virtual bool IsUnderline { get; set; } #endregion #region 폰트 가중치 - FontWeight /// <summary> /// 폰트 가중치 /// </summary> public virtual FontWeight FontWeight { get; set; } #endregion #region 텍스트 장식들 - TextDecorations /// <summary> /// 텍스트 장식들 /// </summary> public virtual TextDecorationCollection TextDecorations { get; set; } #endregion #region 폰트 스타일 - FontStyle /// <summary> /// 스타일 /// </summary> public virtual FontStyle FontStyle { get; set; } #endregion #region 텍스트 정렬 - TextAlignment /// <summary> /// 텍스트 정렬 /// </summary> public virtual TextAlignment TextAlignment { get; set; } #endregion #region 텍스트 - Text /// <summary> /// 텍스트 /// </summary> public virtual string Text { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainViewModel() /// <summary> /// 생성자 /// </summary> public MainViewModel() { TextAlignment = TextAlignment.Left; SetDefaultText(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 볼드체 여부 변경시 처리하기 - OnIsBoldChanged() /// <summary> /// 볼드체 여부 변경시 처리하기 /// </summary> public void OnIsBoldChanged() { FontWeight = IsBold ? FontWeights.Bold : FontWeights.Normal; } #endregion #region 이탤릭체 여부 변경시 처리하기 - OnIsItalicChanged() /// <summary> /// 이탤릭체 여부 변경시 처리하기 /// </summary> public void OnIsItalicChanged() { FontStyle = IsItalic ? FontStyles.Italic : FontStyles.Normal; } #endregion #region 밑줄 여부 변경시 처리하기 - OnIsUnderlineChanged() /// <summary> /// 밑줄 여부 변경시 처리하기 /// </summary> public void OnIsUnderlineChanged() { TextDecorations = IsUnderline ? System.Windows.TextDecorations.Underline : new TextDecorationCollection(); } #endregion #region 파일 열기 - OpenFile() /// <summary> /// 파일 열기 /// </summary> public void OpenFile() { SetDefaultText(); } #endregion #region 새 파일 만들기 실행 가능 여부 구하기 - CanNewFile() /// <summary> /// 새 파일 만들기 실행 가능 여부 구하기 /// </summary> /// <returns>새 파일 실행 가능 여부</returns> public bool CanNewFile() { return true; } #endregion #region 새 파일 만들기 - NewFile() /// <summary> /// 새 파일 만들기 /// </summary> public void NewFile() { Text = null; } #endregion #region 정렬 설정하기 - SetAlignment(parameter) /// <summary> /// 정렬 설정하기 /// </summary> /// <param name="parameter">파라미터</param> public void SetAlignment(object parameter) { TextAlignment = ((TextAlignment)parameter); } #endregion #region 디폴트 텍스트 설정하기 - SetDefaultText() /// <summary> /// 디폴트 텍스트 설정하기 /// </summary> private void SetDefaultText() { Text = "Text"; } #endregion } } |