
<UserControl x:Class="Platform.Controls.ComponentContainer.RtfEditorBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:RtfEditor="clr-namespace:Platform.Controls.ComponentContainer"
             Focusable="True"
             Loaded="RtfEditor_Loaded"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ObjectDataProvider x:Key="FontListKlasse"
                            ObjectType="{x:Type RtfEditor:FontList}"
                            d:IsDataSource="True" />
        <ObjectDataProvider x:Key="FontHeightKlasse"
                            ObjectType="{x:Type RtfEditor:FontHeight}"
                            d:IsDataSource="True" />
        <Style x:Key="formatComboxboxStyle" TargetType="{x:Type ComboBox}">
            <Setter Property="FontFamily" Value="宋体" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Height" Value="23" />
            <Setter Property="Margin" Value="1" />
        </Style>
        <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="FontFamily" Value="宋体" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Width" Value="23" />
            <Setter Property="Height" Value="23" />
            <Setter Property="Margin" Value="1" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="bd"
                                Background="#FFEFF1F3"
                                BorderBrush="{x:Null}"
                                BorderThickness="0">
                            <ContentPresenter x:Name="content"
                                              HorizontalAlignment="Center"
                                              VerticalAlignment="Center"
                                              Content="{TemplateBinding Content}" />
                        </Border>

                        <!--  触发器  -->
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="true">
                                <Setter TargetName="bd" Property="BorderBrush" Value="#FFDECFAC" />
                                <Setter TargetName="bd" Property="Background" Value="#FFFFE876" />
                                <Setter TargetName="bd" Property="BorderThickness" Value="1" />
                                <Setter TargetName="bd" Property="CornerRadius" Value="3" />
                                <Setter Property="Cursor" Value="Hand" />
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="bd" Property="BorderBrush" Value="#FFDECFAC" />
                                <Setter TargetName="bd" Property="Background" Value="#FFFFE876" />
                                <Setter TargetName="bd" Property="BorderThickness" Value="1" />
                                <Setter TargetName="bd" Property="CornerRadius" Value="3" />
                                <Setter Property="Cursor" Value="Hand" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ImgStyle" TargetType="{x:Type Image}">
            <Setter Property="Width" Value="17" />
            <Setter Property="Height" Value="17" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Stretch" Value="Fill" />
            <Setter Property="Margin" Value="2,4" />
        </Style>

    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Border Name="toolBarPanel"
                Grid.Row="0"
                Height="30"
                BorderBrush="#5555"
                BorderThickness="1"
                CornerRadius="3"
                Focusable="True"
                Style="{x:Null}">
            <Border.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientBrush.GradientStops>
                        <GradientStopCollection>
                            <GradientStop Offset="1" Color="#FFEFF1F3" />
                        </GradientStopCollection>
                    </GradientBrush.GradientStops>
                </LinearGradientBrush>
            </Border.Background>
            <WrapPanel Grid.Row="0"
                       VerticalAlignment="Top"
                       FocusManager.IsFocusScope="True"
                       Orientation="Horizontal"
                       Style="{x:Null}">
                <Button x:Name="ToolStripButtonOpen"
                        Click="ToolStripButtonOpen_Click"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="打开(Ctrl+O)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/fileopen.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonCut"
                        Command="ApplicationCommands.Cut"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="剪切(Ctrl+X)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Cut.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonCopy"
                        Command="ApplicationCommands.Copy"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="复制(Ctrl+C)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Copy.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonPaste"
                        Command="ApplicationCommands.Paste"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="粘贴(Ctrl+V)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Paste.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>

                </Button>
                <Button x:Name="ToolStripButtonUndo"
                        Command="ApplicationCommands.Undo"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="撤销(Ctrl+Z)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Undo.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonRedo"
                        Command="ApplicationCommands.Redo"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="重做(Ctrl+Y)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Redo.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <ComboBox x:Name="Fonttype"
                          DropDownClosed="Fonttype_DropDownClosed"
                          ItemsSource="{Binding Mode=OneWay,
                                                Source={StaticResource FontListKlasse}}"
                          Style="{StaticResource formatComboxboxStyle}" />
                <ComboBox x:Name="Fontheight"
                          DropDownClosed="Fontheight_DropDownClosed"
                          ItemsSource="{Binding Mode=OneWay,
                                                Source={StaticResource FontHeightKlasse}}"
                          Style="{StaticResource formatComboxboxStyle}" />
                <Button x:Name="ToolStripButtonTextcolor"
                        Click="ToolStripButtonTextcolor_Click"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Textcolor.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonBackcolor"
                        Click="ToolStripButtonBackcolor_Click"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Backcolor.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonBold"
                        Command="EditingCommands.ToggleBold"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="加粗(Ctrl+B)">
                    <Button.Content>
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontSize="15"
                                   FontWeight="Bold"
                                   Text="B" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonItalic"
                        Command="EditingCommands.ToggleItalic"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="倾斜(Ctrl+I)">
                    <Button.Content>
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontSize="15"
                                   FontStyle="Italic"
                                   FontWeight="Bold"
                                   Text="I" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonUnderline"
                        Command="EditingCommands.ToggleUnderline"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="下划线(Ctrl+U)">
                    <Button.Content>
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontSize="15"
                                   FontWeight="Bold"
                                   Text="U"
                                   TextDecorations="Underline" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonStrikeout"
                        Click="ToolStripButtonStrikeout_Click"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="删除线">
                    <Button.Content>
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontSize="15"
                                   FontWeight="Bold"
                                   Text="S"
                                   TextDecorations="Strikethrough" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonAlignLeft"
                        Command="EditingCommands.AlignLeft"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="文本左对齐(Ctrl+L)">
                    <Button.Content>

                        <Image Source="/Platform.Controls;component/Resource/AlignLeft.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>

                </Button>
                <Button x:Name="ToolStripButtonAlignCenter"
                        Command="EditingCommands.AlignCenter"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="居中对齐(Ctrl+E)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/AlignCenter.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonAlignRight"
                        Command="EditingCommands.AlignRight"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="右对齐(Ctrl+R)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/AlignRight.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonAlignFullJustify"
                        Command="EditingCommands.AlignJustify"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="两端对齐(Ctrl+J)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/AlignFullJustify.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonIndent"
                        Command="EditingCommands.IncreaseIndentation"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="增加缩进">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/Indent.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonIndentDelete"
                        Command="EditingCommands.DecreaseIndentation"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="减少缩进">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/IndentRemove.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonBulletList"
                        Command="EditingCommands.ToggleBullets"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="符号列表">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/listbullets.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button x:Name="ToolStripButtonNumbersList"
                        Command="EditingCommands.ToggleNumbering"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="编号列表">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/listnumbering.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button Command="EditingCommands.IncreaseFontSize"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="增大字体(Ctrl + &gt;)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/CharacterGrowFont.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
                <Button Command="EditingCommands.DecreaseFontSize"
                        CommandTarget="{Binding ElementName=RichTextControl}"
                        Style="{StaticResource ButtonStyle}"
                        ToolTip="减小字体(Ctrl+ &lt;)">
                    <Button.Content>
                        <Image Source="/Platform.Controls;component/Resource/CharacterShrinkFont.png" Style="{StaticResource ImgStyle}" />
                    </Button.Content>
                </Button>
            </WrapPanel>
        </Border>

        <!--  文本区域  -->
        <RichTextBox x:Name="RichTextControl"
                     Grid.Row="1"
                     MinWidth="400"
                     MinHeight="200"
                     MaxWidth="1000"
                     AcceptsReturn="True"
                     AcceptsTab="True"
                     Focusable="True"
                     FocusManager.IsFocusScope="True"
                     FontFamily="宋体"
                     HorizontalScrollBarVisibility="Auto"
                     KeyDown="RichTextControl_KeyDown"
                     KeyUp="RichTextControl_KeyUp"
                     SpellCheck.IsEnabled="False"
                     TextChanged="RichTextControl_TextChanged"
                     VerticalScrollBarVisibility="Auto" />
    </Grid>
</UserControl>

