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

TestProject.zip
다운로드

▶ TestProgressIndicatorService.cs

using System;
using System.Windows.Threading;

using DevExpress.Services;
using DevExpress.Xpf.Editors;

namespace TestProject
{
    /// <summary>
    /// 테스트 진행 지시자 서비스
    /// </summary>
    public class TestProgressIndicatorService : IProgressIndicationService
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 진행 바 에디터
        /// </summary>
        private ProgressBarEdit progressBarEdit;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 지시자 - Indicator

        /// <summary>
        /// 지시자
        /// </summary>
        public ProgressBarEdit Indicator
        {
            get
            {
                return this.progressBarEdit;
            }
            set
            {
                this.progressBarEdit = value;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - TestProgressIndicatorService(serviceProvider, progressBarEdit)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="serviceProvider">서비스 제공자</param>
        /// <param name="progressBarEdit">진행 바 에디터</param>
        public TestProgressIndicatorService(IServiceProvider serviceProvider, ProgressBarEdit progressBarEdit)
        {
            this.progressBarEdit = progressBarEdit;
        }

        #endregion
        
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region (IProgressIndicationService) 시작하기 - Begin(displayName, minimumProgress, maximumProgress, currentProgress)

        /// <summary>
        /// 시작하기
        /// </summary>
        /// <param name="displayName">디스플레이명</param>
        /// <param name="minimumProgress">최소 진행</param>
        /// <param name="maximumProgress">최대 진행</param>
        /// <param name="currentProgress">현재 진행</param>
        public void Begin(string displayName, int minimumProgress, int maximumProgress, int currentProgress)
        {
            this.progressBarEdit.Minimum    = minimumProgress;
            this.progressBarEdit.Maximum    = maximumProgress;
            this.progressBarEdit.EditValue  = currentProgress;
            this.progressBarEdit.Visibility = System.Windows.Visibility.Visible;

            Refresh();
        }

        #endregion
        #region (IProgressIndicationService) 종료하기 - End()

        /// <summary>
        /// 종료하기
        /// </summary>
        public void End()
        {
            this.progressBarEdit.Visibility = System.Windows.Visibility.Collapsed;

            Refresh();
        }

        #endregion
        #region (IProgressIndicationService) 진행 설정하기 - SetProgress(currentProgress)

        /// <summary>
        /// 진행 설정하기
        /// </summary>
        /// <param name="currentProgress">현재 진행</param>
        public void SetProgress(int currentProgress)
        {
            this.progressBarEdit.EditValue = currentProgress;

            Refresh();
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 갱신하기 - Refresh()

        /// <summary>
        /// 갱신하기
        /// </summary>
        private void Refresh()
        {
            Action action = delegate() { };

            this.progressBarEdit.Dispatcher.Invoke(DispatcherPriority.Render, action);
        }

        #endregion
    }
}

 

728x90

 

▶ 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:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
    xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit"
    Width="800"
    Height="600"
    Title="시간이 걸리는 작업을 위한 진행 지시자 구현하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"    />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Button x:Name="mailMergeButton"
            Margin="0 0 0 10"
            Width="200"
            Height="25"
            HorizontalAlignment="Left"
            Content="Mail Merge"
            Click="mailMergeButton_Click" />
        <dx:DXTabControl x:Name="dxTabControl" Grid.Row="1"
            SelectionChanged="dxTabControl_SelectionChanged">
            <dx:DXTabItem Header="Template">
                <dxre:RichEditControl x:Name="richEditControl"
                    Loaded="richEditControl_Loaded"
                    MailMergeStarted="richEditControl_MailMergeStarted"
                    MailMergeRecordStarted="richEditControl_MailMergeRecordStarted"
                    MailMergeRecordFinished="richEditControl_MailMergeRecordFinished"
                    MailMergeFinished="richEditControl_MailMergeFinished" />
            </dx:DXTabItem>
            <dx:DXTabItem Header="Result">
                <dxre:RichEditControl x:Name="richEditControl2" />
            </dx:DXTabItem>
        </dx:DXTabControl>
        <dxe:ProgressBarEdit x:Name="progressBarControl" Grid.Row="2"
            Margin="0 10 0 0"
            Visibility="Collapsed" />
    </Grid>
</Window>

 

300x250

 

▶ MainWindow.xaml.cs

using System.Threading;
using System.Windows;

using DevExpress.Services;
using DevExpress.Xpf.Core;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

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

        #region 생성자 - MainWindow()

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

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 메일 병합 버튼 클릭시 처리하기 - mailMergeButton_Click(sender, e)

        /// <summary>
        /// 메일 병합 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void mailMergeButton_Click(object sender, RoutedEventArgs e)
        {
            MailMergeOptions mailMergeOptions = this.richEditControl.Document.CreateMailMergeOptions();

            mailMergeOptions.MergeMode = MergeMode.NewSection;

            this.richEditControl.Document.MailMerge(mailMergeOptions, this.richEditControl2.Document);

            this.dxTabControl.SelectedIndex = 1;
        }

        #endregion
        #region DX 탭 컨트롤 선택 변경시 처리하기 - dxTabControl_SelectionChanged(sender, e)

        /// <summary>
        /// DX 탭 컨트롤 선택 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void dxTabControl_SelectionChanged(object sender, TabControlSelectionChangedEventArgs e)
        {
            switch(this.dxTabControl.SelectedIndex)
            {
                case 0 : this.mailMergeButton.IsEnabled = true;  break;
                case 1 : this.mailMergeButton.IsEnabled = false; break;
            }
        }

        #endregion
        #region 리치 에디트 컨트롤 로드시 처리하기 - richEditControl_Loaded(sender, e)

        /// <summary>
        /// 리치 에디트 컨트롤 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void richEditControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.richEditControl.ApplyTemplate();

            this.richEditControl.LoadDocument("Docs\\invitation.docx");

            this.richEditControl.Options.MailMerge.DataSource = new SampleData();
        }

        #endregion
        #region 리치 에디트 컨트롤 메일 병합 시작시 처리하기 - richEditControl_MailMergeStarted(sender, e)

        /// <summary>
        /// 리치 에디트 컨트롤 메일 병합 시작시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void richEditControl_MailMergeStarted(object sender, MailMergeStartedEventArgs e)
        {
           this.richEditControl.ReplaceService<IProgressIndicationService>(new TestProgressIndicatorService(this.richEditControl, this.progressBarControl));
        }

        #endregion
        #region 리치 에디트 컨트롤 메일 병합 레코드 시작시 처리하기 - richEditControl_MailMergeRecordStarted(sender, e)

        /// <summary>
        /// 리치 에디트 컨트롤 메일 병합 레코드 시작시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void richEditControl_MailMergeRecordStarted(object sender, MailMergeRecordStartedEventArgs e)
        {
            Thread.Sleep(100);
        }

        #endregion
        #region 리치 에디트 컨트롤 메일 병합 레코드 종료시 처리하기 - richEditControl_MailMergeRecordFinished(sender, e)

        /// <summary>
        /// 리치 에디트 컨트롤 메일 병합 레코드 종료시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void richEditControl_MailMergeRecordFinished(object sender, MailMergeRecordFinishedEventArgs e)
        {
            e.RecordDocument.AppendDocumentContent("Docs\\bungalow.docx", DocumentFormat.OpenXml);
        }

        #endregion
        #region 리치 에디트 컨트롤 메일 병합 종료시 처리하기 - richEditControl_MailMergeFinished(sender, e)

        /// <summary>
        /// 리치 에디트 컨트롤 메일 병합 종료시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void richEditControl_MailMergeFinished(object sender, MailMergeFinishedEventArgs e)
        {
            this.richEditControl.RemoveService(typeof(IProgressIndicationService));
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요