첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ 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"
    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>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Windows;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        #endregion
    }
}

 

▶ MainViewModel.cs

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
    }    
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요