chr
2024-08-16 fdc02492963bd1ec69b37c28221603a6f0665016
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
<UserControl x:Class="PdmSwPlugin.UI.CustomRichBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:PdmSwPlugin.UI"
             mc:Ignorable="d" 
             Loaded="UserControl_Loaded"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Stretch"
             x:Name="main"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/PdmSwPlugin.UI;component/Resources/Icons.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
 
    <Grid>
        <Grid.Resources>
            <ResourceDictionary>
                <Style TargetType="Button">
                    <Setter Property="Margin" Value="2"></Setter>
                    <Setter Property="Width" Value="30"></Setter>
                    <Setter Property="Height" Value="30"></Setter>
                    <Setter Property="Background" Value="#fff"></Setter>
                    <Setter Property="Padding" Value="3"></Setter>
                    <Setter Property="BorderBrush" Value="#eeeeee"></Setter>
                    <Setter Property="BorderThickness" Value="1"></Setter>
                </Style>
            </ResourceDictionary>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel x:Name="toolBar" Orientation="Horizontal" Grid.Row="0" MinHeight="25">
 
            <Button ToolTip="撤销" Command="ApplicationCommands.Undo" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_undo}" Stretch="Fill" Fill="#8a8a8a"></Path>
            </Button>
            <Button ToolTip="重做" Command="ApplicationCommands.Redo" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_redo}" Stretch="Fill" Fill="#8a8a8a"></Path>
            </Button>
            <GridSplitter Width="1" Margin="3 2 3 2" Background="LightGray" IsEnabled="False"></GridSplitter>
            <Button ToolTip="加粗" Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_bold}" Stretch="Fill" Fill="Black"></Path>
            </Button>
            <Button ToolTip="斜体" Command="EditingCommands.ToggleItalic" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_italic}" Stretch="Fill" Fill="LightGray"></Path>
            </Button>
            <Button ToolTip="下划线" Command="EditingCommands.ToggleUnderline" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_underline}" Stretch="Fill" Fill="Gray"></Path>
            </Button>
            <Button ToolTip="删除线" Click="Setting_Click" Tag="StrikeLine">
                <Path Data="{StaticResource icon_strikeline}" Stretch="Fill" Fill="Black"></Path>
            </Button>
            <Button ToolTip="左对齐" Command="EditingCommands.AlignLeft" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_left}" Stretch="Fill" Fill="Black" Stroke="LimeGreen"></Path>
            </Button>
            <Button ToolTip="居中对齐" Command="EditingCommands.AlignCenter" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_center}" Stretch="Fill" Fill="Black" Stroke="LimeGreen"></Path>
            </Button>
            <Button ToolTip="右对齐" Command="EditingCommands.AlignRight" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_right}" Stretch="Fill" Fill="Black" Stroke="LimeGreen"></Path>
            </Button>
            <Button ToolTip="两端对齐" Command="EditingCommands.AlignJustify" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_justify}" Stretch="Fill" Fill="Black" Stroke="LimeGreen"></Path>
            </Button>
            <Button ToolTip="缩进" Command="EditingCommands.IncreaseIndentation" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_addident}" Stretch="Fill" Fill="DimGray"></Path>
            </Button>
            <Button ToolTip="减少缩进" Command="EditingCommands.DecreaseIndentation" CommandTarget="{Binding ElementName=richTextBox}">
                <Path Data="{StaticResource icon_lessident}" Stretch="Fill" Fill="DimGray"></Path>
            </Button>
            <Button ToolTip="上标" Click="Setting_Click" Tag="Super">
                <Path Data="{StaticResource icon_upper}" Stretch="Fill" Fill="CadetBlue"></Path>
            </Button>
            <Button ToolTip="下标" Click="Setting_Click" Tag="Sub">
                <Path Data="{StaticResource icon_down}" Stretch="Fill" Fill="CadetBlue"></Path>
            </Button>
            <GridSplitter Width="1" Margin="3 2 3 2" Background="LightGray" IsEnabled="False"></GridSplitter>
 
            <Grid Background="White" Width="42" Height="30" Margin="3">
                <ComboBox Width="42" Height="30" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Center" BorderBrush="White" Background="White" x:Name="fontSizeComb"
          SelectionChanged="FontSize_SelectionChanged">
                    <ComboBoxItem Content="12"></ComboBoxItem>
                    <ComboBoxItem Content="14"></ComboBoxItem>
                    <ComboBoxItem Content="16"></ComboBoxItem>
                    <ComboBoxItem Content="32"></ComboBoxItem>
                    <ComboBoxItem Content="48"></ComboBoxItem>
                    <ComboBoxItem Content="64"></ComboBoxItem>
                </ComboBox>
                <Button IsEnabled="False" ToolTip="字号" Width="30" Height="30" Padding="0" Margin="0" 
                        HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding ElementName=fontSizeComb, Path=SelectedItem.Content}">
 
                </Button>
            </Grid>
 
            <Grid Background="White" Width="42" Height="30" Margin="3">
                <ComboBox Width="42" Height="30" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Center" 
                      BorderBrush="White" Background="White" Name="combBackground"
                      SelectionChanged="Color_SelectionChanged">
                    <ComboBoxItem Background="#000000" Content="#000000"></ComboBoxItem>
                    <ComboBoxItem Background="#FF0000" Content="#FF0000"></ComboBoxItem>
                    <ComboBoxItem Background="#00FF00" Content="#00FF00"></ComboBoxItem>
                    <ComboBoxItem Background="#0000FF" Content="#0000FF"></ComboBoxItem>
                    <ComboBoxItem Background="#00AA00" Content="#00AA00"></ComboBoxItem>
                    <ComboBoxItem Background="#AA0000" Content="#AA0000"></ComboBoxItem>
                    <ComboBoxItem Background="#0000AA" Content="#0000AA"></ComboBoxItem>
                    <ComboBoxItem Background="#AA00CC" Content="#AA00CC"></ComboBoxItem>
                    <ComboBoxItem Background="#00BBCC" Content="#00BBCC"></ComboBoxItem>
                    <ComboBoxItem Background="#555555" Content="#555555"></ComboBoxItem>
                    <ComboBoxItem Background="#AAAAAA" Content="#AAAAAA"></ComboBoxItem>
                    <ComboBoxItem Background="#BBBBBB" Content="#BBBBBB"></ComboBoxItem>
                    <ComboBoxItem Background="#CCCCCC" Content="#CCCCCC"></ComboBoxItem>
                    <ComboBoxItem Background="#DDDDDD" Content="#DDDDDD"></ComboBoxItem>
                    <ComboBoxItem Background="#EEEEEE" Content="#EEEEEE"></ComboBoxItem>
                    <ComboBoxItem Background="#FFFFFF" Content="#FFFFFF"></ComboBoxItem>
                </ComboBox>
                <Button ToolTip="背景色" Width="30" Height="30" Padding="0" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Center">
                    <Path Data="{StaticResource icon_background}" Stretch="Fill"  Fill="{Binding ElementName=combBackground, Path=SelectedItem.Background}"  ></Path>
                </Button>
            </Grid>
            <Grid Background="White" Width="42" Height="30" Margin="3">
                <ComboBox Width="42" Height="30" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Center"
                      BorderBrush="White" Background="White" Name="combForeground"
                      SelectionChanged="Color_SelectionChanged">
                    <ComboBoxItem Background="#000000" Content="#000000"></ComboBoxItem>
                    <ComboBoxItem Background="#FF0000" Content="#FF0000"></ComboBoxItem>
                    <ComboBoxItem Background="#00FF00" Content="#00FF00"></ComboBoxItem>
                    <ComboBoxItem Background="#0000FF" Content="#0000FF"></ComboBoxItem>
                    <ComboBoxItem Background="#00AA00" Content="#00AA00"></ComboBoxItem>
                    <ComboBoxItem Background="#AA0000" Content="#AA0000"></ComboBoxItem>
                    <ComboBoxItem Background="#0000AA" Content="#0000AA"></ComboBoxItem>
                    <ComboBoxItem Background="#AA00CC" Content="#AA00CC"></ComboBoxItem>
                    <ComboBoxItem Background="#00BBCC" Content="#00BBCC"></ComboBoxItem>
                    <ComboBoxItem Background="#555555" Content="#555555"></ComboBoxItem>
                    <ComboBoxItem Background="#AAAAAA" Content="#AAAAAA"></ComboBoxItem>
                    <ComboBoxItem Background="#BBBBBB" Content="#BBBBBB"></ComboBoxItem>
                    <ComboBoxItem Background="#CCCCCC" Content="#CCCCCC"></ComboBoxItem>
                    <ComboBoxItem Background="#DDDDDD" Content="#DDDDDD"></ComboBoxItem>
                    <ComboBoxItem Background="#EEEEEE" Content="#EEEEEE"></ComboBoxItem>
                    <ComboBoxItem Background="#FFFFFF" Content="#FFFFFF"></ComboBoxItem>
                </ComboBox>
                <Button ToolTip="前景色" Width="30" Height="30" Padding="0" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Center">
                    <Path Data="{StaticResource icon_foreground}" Stretch="Fill"  Fill="{Binding ElementName=combForeground, Path=SelectedItem.Background}"></Path>
                </Button>
            </Grid>
            <Button ToolTip="图像" Click="Setting_Click" Tag="Image">
                <Path Data="{StaticResource icon_img}" Stretch="Fill" Fill="Goldenrod"></Path>
            </Button>
        </StackPanel>
        <RichTextBox x:Name="richTextBox" AcceptsTab="True" Grid.Row="1" BorderThickness="1" 
                     BorderBrush="Black" Margin="2" Padding="2" ScrollViewer.CanContentScroll="True"
                     PreviewKeyDown="UserControl_KeyDown"
                     HorizontalAlignment="Stretch"
                     ScrollViewer.VerticalScrollBarVisibility="Auto">
            <RichTextBox.Resources>
                <Style TargetType="Paragraph">
                    <Setter Property="Margin" Value="0"/>
                </Style>
            </RichTextBox.Resources>
 
            <RichTextBox.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="复制" Click="Copy_Click"/>
                    <MenuItem Header="粘贴" Click="Paste_Click">
                        <!--<MenuItem.Style>
                            <Style TargetType="{x:Type MenuItem}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=PlacementTarget.IsReadOnly}" Value="True">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Style>-->
                    </MenuItem>
                </ContextMenu>
            </RichTextBox.ContextMenu>
        </RichTextBox>
    </Grid>
</UserControl>