첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
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:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
    xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
    xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit"
    Width="800"
    Height="600"
    Title="AutoCorrect 이벤트 처리하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <ResourceDictionary>
            <dxre:RichEditUICommand           x:Key="RichEditUICommandKey"           />
            <dxre:RichEditStringIdConverter   x:Key="RichEditStringIdConverterKey"   />
            <dxre:DefaultBarItemDataTemplates x:Key="DefaultBarItemDataTemplatesKey" />
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <dxb:BarManager x:Name="barManager"
            ToolbarGlyphSize="Small">
            <dxb:BarManager.Items>
                <dxb:BarButtonItem x:Name="fileNewBarButtonItem"
                    Command="{Binding Path=FileNew, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileOpenBarButtonItem"
                    Command="{Binding Path=FileOpen, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileSaveBarButtonItem"
                    Command="{Binding Path=FileSave, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileSaveAsBarButtonItem"
                    Command="{Binding Path=FileSaveAs, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileQuickPrintBarButtonItem"
                    Command="{Binding Path=FileQuickPrint, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="filePrintBarButtonItem"
                    Command="{Binding Path=FilePrint, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="filePrintPreviewBarButtonItem"
                    Command="{Binding Path=FilePrintPreview, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editUndoBarButtonItem"
                    Command="{Binding Path=EditUndo, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editRedoBarButtonItem"
                    Command="{Binding Path=EditRedo, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editPasteBarButtonItem"
                    Command="{Binding Path=EditPaste, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editCutBarButtonItem"
                    Command="{Binding Path=EditCut, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editCopyBarButtonItem"
                    Command="{Binding Path=EditCopy, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editPasteSpecialBarButtonItem"
                    Command="{Binding Path=EditPasteSpecial, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup Name="fontBarButtonGroup">
                    <dxb:BarEditItemLink BarItemName="formatFontNameBarEditItem" />
                    <dxb:BarEditItemLink BarItemName="formatFontSizeBarEditItem" />
                </dxr:BarButtonGroup>
                <dxb:BarEditItem x:Name="formatFontNameBarEditItem"
                    Command="{Binding Path=FormatFontName, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}"
                    EditWidth="150"
                    Content="">
                    <dxb:BarEditItem.EditSettings>
                        <dxre:FontComboBoxEditSettings />
                    </dxb:BarEditItem.EditSettings>
                </dxb:BarEditItem>
                <dxb:BarEditItem x:Name="formatFontSizeBarEditItem"
                    Command="{Binding Path=FormatFontSize, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}"
                    EditWidth="50"
                    Content="">
                    <dxb:BarEditItem.EditSettings>
                        <dxre:FontSizeComboBoxEditSettings OfficeFontSizeProvider="{Binding ElementName=richEditControl}" />
                    </dxb:BarEditItem.EditSettings>
                </dxb:BarEditItem>
                <dxr:BarButtonGroup Name="fontSizeBarButtonGroup">
                    <dxb:BarButtonItemLink BarItemName="formatIncreaseFontSizeBarButtonItem" />
                    <dxb:BarButtonItemLink BarItemName="formatDecreaseFontSizeBarButtonItem" />
                </dxr:BarButtonGroup>
                <dxb:BarButtonItem x:Name="formatIncreaseFontSizeBarButtonItem"
                    Command="{Binding Path=FormatIncreaseFontSize, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="formatDecreaseFontSizeBarButtonItem"
                    Command="{Binding Path=FormatDecreaseFontSize, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup x:Name="clearFormattingBarButtonGroup">
                    <dxb:BarButtonItemLink BarItemName="formatClearFormattingBarButtonItem" />
                </dxr:BarButtonGroup>
                <dxb:BarButtonItem x:Name="formatClearFormattingBarButtonItem"
                    Command="{Binding Path=FormatClearFormatting, 
                        Mode=OneTime, 
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup Name="fontShapeBarButtonGroup">
                    <dxb:BarCheckItemLink BarItemName="formatFontBoldBarCheckItem"            />
                    <dxb:BarCheckItemLink BarItemName="formatFontItalicBarCheckItem"          />
                    <dxb:BarCheckItemLink BarItemName="formatFontUnderlineBarCheckItem"       />
                    <dxb:BarCheckItemLink BarItemName="formatFontDoubleUnderlineBarCheckItem" />
                    <dxb:BarCheckItemLink BarItemName="formatFontStrikeoutBarCheckItem"       />
                    <dxb:BarCheckItemLink BarItemName="formatFontDoubleStrikeoutBarCheckItem" />
                    <dxb:BarCheckItemLink BarItemName="formatFontSuperscriptBarCheckItem"     />
                    <dxb:BarCheckItemLink BarItemName="formatFontSubscriptBarCheckItem"       />
                    <dxb:BarSubItemLink   BarItemName="editChangeCaseBarSubItem"              />
                </dxr:BarButtonGroup>
                <dxb:BarCheckItem x:Name="formatFontBoldBarCheckItem"
                    Command="{Binding Path=FormatFontBold,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatFontItalicBarCheckItem"
                    Command="{Binding Path=FormatFontItalic,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatFontUnderlineBarCheckItem"
                    Command="{Binding Path=FormatFontUnderline,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatFontDoubleUnderlineBarCheckItem"
                    Command="{Binding Path=FormatFontDoubleUnderline,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatFontStrikeoutBarCheckItem"
                    Command="{Binding Path=FormatFontStrikeout,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatFontDoubleStrikeoutBarCheckItem"
                    Command="{Binding Path=FormatFontDoubleStrikeout,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatFontSuperscriptBarCheckItem"
                    Command="{Binding Path=FormatFontSuperscript,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatFontSubscriptBarCheckItem"
                    Command="{Binding Path=FormatFontSubscript,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarSubItem x:Name="editChangeCaseBarSubItem"
                    Command="{Binding Path=EditChangeCase,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}">
                    <dxb:BarButtonItemLink BarItemName="editMakeUpperCaseBarButtonItem" />
                    <dxb:BarButtonItemLink BarItemName="editMakeLowerCaseBarButtonItem" />
                    <dxb:BarButtonItemLink BarItemName="editToggleCaseBarButtonItem"    />
                </dxb:BarSubItem>
                <dxb:BarButtonItem x:Name="editMakeUpperCaseBarButtonItem"
                    Command="{Binding Path=EditMakeUpperCase,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editMakeLowerCaseBarButtonItem"
                    Command="{Binding Path=EditMakeLowerCase,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editToggleCaseBarButtonItem"
                    Command="{Binding Path=EditToggleCase,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup x:Name="fontColorBarButtonGroup">
                    <dxre:BarSplitButtonColorEditItemLink BarItemName="formatFontBackColorBarSplitButtonColorEditItem" />
                    <dxre:BarSplitButtonColorEditItemLink BarItemName="formatFontForeColorBarSplitButtonColorEditItem" />
                </dxr:BarButtonGroup>
                <dxre:BarSplitButtonColorEditItem x:Name="formatFontBackColorBarSplitButtonColorEditItem"
                    Command="{Binding Path=FormatFontBackColor,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}">
                    <dxre:BarSplitButtonColorEditItem.PopupControl>
                        <dxb:PopupControlContainerInfo>
                            <dxe:ColorEdit
                                ChipMargin="5"
                                ChipSize="Large"
                                ColumnCount="5"
                                EditValue="{Binding ElementName=formatFontBackColorBarSplitButtonColorEditItem,
                                    Mode=TwoWay,
                                    Path=EditValue}"
                                ShowBorder="False"
                                ShowDefaultColorButton="False"
                                ShowMoreColorsButton="False"
                                ShowNoColorButton="True">
                                <dxe:ColorEdit.Palettes>
                                    <dxre:CharactersBackgroundColorPaletteCollection />
                                </dxe:ColorEdit.Palettes>
                            </dxe:ColorEdit>
                        </dxb:PopupControlContainerInfo>
                    </dxre:BarSplitButtonColorEditItem.PopupControl>
                </dxre:BarSplitButtonColorEditItem>
                <dxre:BarSplitButtonColorEditItem x:Name="formatFontForeColorBarSplitButtonColorEditItem"
                    Command="{Binding Path=FormatFontForeColor,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}">
                    <dxre:BarSplitButtonColorEditItem.PopupControl>
                        <dxb:PopupControlContainerInfo>
                            <dxe:ColorEdit
                                EditValue="{Binding ElementName=formatFontForeColorBarSplitButtonColorEditItem,
                                    Mode=TwoWay,
                                    Path=EditValue}"
                                ShowBorder="False" />
                        </dxb:PopupControlContainerInfo>
                    </dxre:BarSplitButtonColorEditItem.PopupControl>
                </dxre:BarSplitButtonColorEditItem>
                <dxr:BarButtonGroup Name="numberingListBarButtonGroup">
                    <dxb:BarCheckItemLink BarItemName="formatBulletedListBarCheckItem"   />
                    <dxb:BarCheckItemLink BarItemName="formatNumberingListBarCheckItem"  />
                    <dxb:BarCheckItemLink BarItemName="formatMultilevelListBarCheckItem" />
                </dxr:BarButtonGroup>
                <dxb:BarCheckItem x:Name="formatBulletedListBarCheckItem"
                    Command="{Binding Path=FormatBulletedList,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatNumberingListBarCheckItem"
                    Command="{Binding Path=FormatNumberingList,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatMultilevelListBarCheckItem"
                    Command="{Binding Path=FormatMultilevelList,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup x:Name="paragraphIndentBarButtonGroup">
                    <dxb:BarButtonItemLink BarItemName="formatDecreaseIndentBarButtonItem" />
                    <dxb:BarButtonItemLink BarItemName="formatIncreaseIndentBarButtonItem" />
                </dxr:BarButtonGroup>
                <dxb:BarButtonItem x:Name="formatDecreaseIndentBarButtonItem"
                    Command="{Binding Path=FormatDecreaseIndent,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="formatIncreaseIndentBarButtonItem"
                    Command="{Binding Path=FormatIncreaseIndent,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup x:Name="showWhitespaceBarButtonGroup">
                    <dxb:BarCheckItemLink BarItemName="viewShowWhitespaceBarCheckItem" />
                </dxr:BarButtonGroup>
                <dxb:BarCheckItem x:Name="viewShowWhitespaceBarCheckItem"
                    Command="{Binding Path=ViewShowWhitespace,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup x:Name="paragraphAlignmentBarButtonGroup">
                    <dxb:BarCheckItemLink BarItemName="formatParagraphAlignLeftBarCheckItem"    />
                    <dxb:BarCheckItemLink BarItemName="formatParagraphAlignCenterBarCheckItem"  />
                    <dxb:BarCheckItemLink BarItemName="formatParagraphAlignRightBarCheckItem"   />
                    <dxb:BarCheckItemLink BarItemName="formatParagraphAlignJustifyBarCheckItem" />
                </dxr:BarButtonGroup>
                <dxb:BarCheckItem x:Name="formatParagraphAlignLeftBarCheckItem"
                    Command="{Binding Path=FormatParagraphAlignLeft,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatParagraphAlignCenterBarCheckItem"
                    Command="{Binding Path=FormatParagraphAlignCenter,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatParagraphAlignRightBarCheckItem"
                    Command="{Binding Path=FormatParagraphAlignRight,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatParagraphAlignJustifyBarCheckItem"
                    Command="{Binding Path=FormatParagraphAlignJustify,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxr:BarButtonGroup x:Name="lineSpacingBarButtonGroup">
                    <dxb:BarSubItemLink BarItemName="formatParagraphLineSpacingBarSubItem" />
                    <dxre:BarSplitButtonColorEditItemLink BarItemName="formatParagraphBackColorBarSplitButtonColorEditItem" />
                </dxr:BarButtonGroup>
                <dxb:BarSubItem x:Name="formatParagraphLineSpacingBarSubItem"
                    Command="{Binding Path=FormatParagraphLineSpacing,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}">
                    <dxb:BarCheckItemLink  BarItemName="formatParagraphLineSpacingSingleBarCheckItem"        />
                    <dxb:BarCheckItemLink  BarItemName="formatParagraphLineSpacingSesquialteralBarCheckItem" />
                    <dxb:BarCheckItemLink  BarItemName="formatParagraphLineSpacingDoubleBarCheckItem"        />
                    <dxb:BarButtonItemLink BarItemName="formatParagraphLineSpacingCustomizeBarCheckItem"     />
                    <dxb:BarButtonItemLink BarItemName="formatParagraphAddSpacingBeforeBarButtonItem"        />
                    <dxb:BarButtonItemLink BarItemName="formatParagraphRemoveSpacingBeforeBarButtonItem"     />
                    <dxb:BarButtonItemLink BarItemName="formatParagraphAddSpacingAfterBarButtonItem"         />
                    <dxb:BarButtonItemLink BarItemName="formatParagraphRemoveSpacingAfterBarButtonItem"      />
                </dxb:BarSubItem>
                <dxb:BarCheckItem x:Name="formatParagraphLineSpacingSingleBarCheckItem"
                    Command="{Binding Path=FormatParagraphLineSpacingSingle,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatParagraphLineSpacingSesquialteralBarCheckItem"
                    Command="{Binding Path=FormatParagraphLineSpacingSesquialteral,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarCheckItem x:Name="formatParagraphLineSpacingDoubleBarCheckItem"
                    Command="{Binding Path=FormatParagraphLineSpacingDouble,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="formatParagraphLineSpacingCustomizeBarCheckItem"
                    Command="{Binding Path=FormatParagraphLineSpacingCustomize,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="formatParagraphAddSpacingBeforeBarButtonItem"
                    Command="{Binding Path=FormatParagraphAddSpacingBefore,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="formatParagraphRemoveSpacingBeforeBarButtonItem"
                    Command="{Binding Path=FormatParagraphRemoveSpacingBefore,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="formatParagraphAddSpacingAfterBarButtonItem"
                    Command="{Binding Path=FormatParagraphAddSpacingAfter,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="formatParagraphRemoveSpacingAfterBarButtonItem"
                    Command="{Binding Path=FormatParagraphRemoveSpacingAfter,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxre:BarSplitButtonColorEditItem x:Name="formatParagraphBackColorBarSplitButtonColorEditItem"
                    Command="{Binding Path=FormatParagraphBackColor,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}">
                    <dxre:BarSplitButtonColorEditItem.PopupControl>
                        <dxb:PopupControlContainerInfo>
                            <dxe:ColorEdit
                                EditValue="{Binding ElementName=formatParagraphBackColorBarSplitButtonColorEditItem,
                                    Mode=TwoWay,
                                    Path=EditValue}"
                                ShowBorder="False"
                                ShowDefaultColorButton="False"
                                ShowNoColorButton="True" />
                        </dxb:PopupControlContainerInfo>
                    </dxre:BarSplitButtonColorEditItem.PopupControl>
                </dxre:BarSplitButtonColorEditItem>
                <dxr:BarButtonGroup x:Name="paragraphBarButtonGroup" />
                <dxre:GalleryStyleItem x:Name="styleGalleryStyleItem"
                    Command="{Binding Path=FormatFontStyle,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}"
                    RichEditControl="{Binding ElementName=richEditControl}">
                    <dxre:GalleryStyleItem.Gallery>
                        <dxre:RichEditStyleGallery
                            MinColCount="3"
                            ColCount="10"
                            IsItemGlyphVisible="False"
                            IsItemDescriptionVisible="False"
                            ItemCaptionTemplate="{Binding Path=StyleGalleryItemCaptionTemplate,
                                Mode=OneTime,
                                Source={StaticResource DefaultBarItemDataTemplatesKey}}"
                            ItemCheckMode="Single" />
                    </dxre:GalleryStyleItem.Gallery>
                </dxre:GalleryStyleItem>
                <dxb:BarButtonItem x:Name="editFindBarButtonItem"
                    Command="{Binding Path=EditFind,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editReplaceBarButtonItem"
                    Command="{Binding Path=EditReplace,
                        Mode=OneTime,
                        Source={StaticResource RichEditUICommandKey}}" />
            </dxb:BarManager.Items>
            <DockPanel>
                <dxr:RibbonControl x:Name="ribbonControl"
                    DockPanel.Dock="Top">
                    <dxr:RibbonDefaultPageCategory>
                        <dxr:RibbonPage x:Name="fileRibbonPage"
                            Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                ConverterParameter=Caption_PageFile,
                                Converter={StaticResource RichEditStringIdConverterKey},
                                Mode=OneTime}">
                            <dxr:RibbonPageGroup x:Name="fileCommonRibbonPageGroup"
                                ShowCaptionButton="False"
                                Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                    ConverterParameter=Caption_GroupCommon,
                                    Converter={StaticResource RichEditStringIdConverterKey},
                                    Mode=OneTime}">
                                <dxb:BarButtonItemLink BarItemName="fileNewBarButtonItem"          />
                                <dxb:BarButtonItemLink BarItemName="fileOpenBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="fileSaveBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="fileSaveAsBarButtonItem"       />
                                <dxb:BarButtonItemLink BarItemName="fileQuickPrintBarButtonItem"   />
                                <dxb:BarButtonItemLink BarItemName="filePrintBarButtonItem"        />
                                <dxb:BarButtonItemLink BarItemName="filePrintPreviewBarButtonItem" />
                                <dxb:BarButtonItemLink BarItemName="editUndoBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="editRedoBarButtonItem"         />
                            </dxr:RibbonPageGroup>
                        </dxr:RibbonPage>
                        <dxr:RibbonPage x:Name="homeRibbonPage"
                            Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                ConverterParameter=Caption_PageHome,
                                Converter={StaticResource RichEditStringIdConverterKey},
                                Mode=OneTime}">
                            <dxr:RibbonPageGroup x:Name="homeClipboardRibbonPageGroup"
                                ShowCaptionButton="False"
                                Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                    ConverterParameter=Caption_GroupClipboard,
                                    Converter={StaticResource RichEditStringIdConverterKey},
                                    Mode=OneTime}">
                                <dxb:BarButtonItemLink BarItemName="editPasteBarButtonItem"        />
                                <dxb:BarButtonItemLink BarItemName="editCutBarButtonItem"          />
                                <dxb:BarButtonItemLink BarItemName="editCopyBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="editPasteSpecialBarButtonItem" />
                            </dxr:RibbonPageGroup>
                            <dxr:RibbonPageGroup x:Name="homeFontRibbonPageGroup"
                                Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                    ConverterParameter=Caption_GroupFont,
                                    Converter={StaticResource RichEditStringIdConverterKey},
                                    Mode=OneTime}"
                                CaptionButtonCommand="{Binding Path=FormatFont,
                                    Mode=OneTime,
                                    Source={StaticResource RichEditUICommandKey}}">
                                <dxr:BarButtonGroupLink BarItemName="fontBarButtonGroup"            />
                                <dxr:BarButtonGroupLink BarItemName="fontSizeBarButtonGroup"        />
                                <dxr:BarButtonGroupLink BarItemName="clearFormattingBarButtonGroup" />
                                <dxr:BarButtonGroupLink BarItemName="fontShapeBarButtonGroup"       />
                                <dxr:BarButtonGroupLink BarItemName="fontColorBarButtonGroup"       />
                            </dxr:RibbonPageGroup>
                            <dxr:RibbonPageGroup x:Name="homeParagraphRibbonPageGroup"
                                Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                    ConverterParameter=Caption_GroupParagraph,
                                    Converter={StaticResource RichEditStringIdConverterKey},
                                    Mode=OneTime}"
                                CaptionButtonCommand="{Binding Path=FormatParagraph,
                                    Mode=OneTime,
                                    Source={StaticResource RichEditUICommandKey}}">
                                <dxr:BarButtonGroupLink BarItemName="numberingListBarButtonGroup"      />
                                <dxr:BarButtonGroupLink BarItemName="paragraphIndentBarButtonGroup"    />
                                <dxr:BarButtonGroupLink BarItemName="showWhitespaceBarButtonGroup"     />
                                <dxr:BarButtonGroupLink BarItemName="paragraphAlignmentBarButtonGroup" />
                                <dxr:BarButtonGroupLink BarItemName="lineSpacingBarButtonGroup"        />
                                <dxr:BarButtonGroupLink BarItemName="paragraphBarButtonGroup"          />
                            </dxr:RibbonPageGroup>
                            <dxr:RibbonPageGroup x:Name="homeStylesRibbonPageGroup"
                                Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                    ConverterParameter=Caption_GroupStyles,
                                    Converter={StaticResource RichEditStringIdConverterKey},
                                    Mode=OneTime}"
                                CaptionButtonCommand="{Binding Path=FormatEditFontStyle,
                                    Mode=OneTime,
                                    Source={StaticResource RichEditUICommandKey}}">
                                <dxre:RibbonStyleGalleryItemLink BarItemName="styleGalleryStyleItem" />
                            </dxr:RibbonPageGroup>
                            <dxr:RibbonPageGroup x:Name="homeEditingRibbonPageGroup"
                                ShowCaptionButton="False"
                                Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                    ConverterParameter=Caption_GroupEditing,
                                    Converter={StaticResource RichEditStringIdConverterKey},
                                    Mode=OneTime}">
                                <dxb:BarButtonItemLink BarItemName="editFindBarButtonItem"    />
                                <dxb:BarButtonItemLink BarItemName="editReplaceBarButtonItem" />
                            </dxr:RibbonPageGroup>
                        </dxr:RibbonPage>
                    </dxr:RibbonDefaultPageCategory>
                </dxr:RibbonControl>
                <dxre:RichEditControl x:Name="richEditControl"
                    BarManager="{Binding ElementName=barManager, Mode=OneTime}"
                    Ribbon="{Binding ElementName=ribbonControl, Mode=OneTime}"
                    Loaded="richEditControl_Loaded" />
            </DockPanel>
        </dxb:BarManager>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Windows;

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.Model;
using DevExpress.XtraRichEdit.Utils;
using DevExpress.XtraRichEdit.Utils.NumberConverters;

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

        #region 생성자 - MainWindow()

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

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #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.CreateNewDocument();

            this.richEditControl.AutoCorrect += new AutoCorrectEventHandler(richEditControl_AutoCorrect);
        }

        #endregion
        #region 리치 에디트 컨트롤 자동 수정시 처리하기 - richEditControl_AutoCorrect(sender, e)

        /// <summary>
        /// 리치 에디트 컨트롤 자동 수정시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void richEditControl_AutoCorrect(object sender, AutoCorrectEventArgs e)
        {
            AutoCorrectInfo autoCorrectInfo = e.AutoCorrectInfo;

            e.AutoCorrectInfo = null;

            if(autoCorrectInfo.Text.Length <= 0)
            {
                return;
            }

            for(;;)
            {
                if(!autoCorrectInfo.DecrementStartPosition())
                {
                    return;
                }

                if(IsSeparator(autoCorrectInfo.Text[0]))
                {
                    return;
                }

                if(autoCorrectInfo.Text[0] == '$')
                {
                    autoCorrectInfo.ReplaceWith = CreateImage("dollar.png");

                    e.AutoCorrectInfo = autoCorrectInfo;

                    return;
                }

                if(autoCorrectInfo.Text[0] == '%')
                {
                    string replace = GetReplaceString(autoCorrectInfo.Text);

                    if(!string.IsNullOrEmpty(replace))
                    {
                        autoCorrectInfo.ReplaceWith = replace;

                        e.AutoCorrectInfo = autoCorrectInfo;
                    }

                    return;
                }
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 분리자 여부 조사하기 - IsSeparator(character)

        /// <summary>
        /// 분리자 여부 조사하기
        /// </summary>
        /// <param name="character">문자</param>
        /// <returns>분리자 여부</returns>
        private bool IsSeparator(char character)
        {
            return character != '%' && (character == '\r' || character == '\n' ||
                Char.IsPunctuation(character) || Char.IsSeparator(character) || Char.IsWhiteSpace(character));
        }

        #endregion
        #region 이미지 생성하기 - CreateImage(fileName)

        /// <summary>
        /// 이미지 생성하기
        /// </summary>
        /// <param name="fileName">파일명</param>
        /// <returns>Image 객체</returns>
        private Image CreateImage(string fileName)
        {
            Image    image;
            Assembly assembly = Assembly.GetExecutingAssembly();

            using(Stream stream = assembly.GetManifestResourceStream("TestProject.Image." + fileName))
            {
                image = Image.FromStream(stream);
            }

            return image;
        }

        #endregion
        #region 대체 문자열 구하기 - GetReplaceString(token)

        /// <summary>
        /// 대체 문자열 구하기
        /// </summary>
        /// <param name="token">토큰</param>
        /// <returns>대체 문자열</returns>
        private string GetReplaceString(string token)
        {
            token = token.ToLower();

            if(token.Length > 2 && token[0] == '%' && token.EndsWith("%"))
            {
                int value;

                if(int.TryParse(token.Substring(1, token.Length - 2), out value))
                {
                    OrdinalBasedNumberConverter converter = OrdinalBasedNumberConverter.CreateConverter(NumberingFormat.CardinalText, LanguageId.English);

                    return converter.ConvertNumber(value);
                }
            }

            switch(token)
            {
                case "%date%" : return DateTime.Now.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);
                case "%time%" : return DateTime.Now.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern);
                default       : return string.Empty;
            }
        }

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

댓글을 달아 주세요