-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml
175 lines (164 loc) · 8.54 KB
/
MainWindow.xaml
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
<Window x:Class="moji.MainWindow"
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:local="clr-namespace:moji"
xmlns:interop="clr-namespace:Walterlv.Demo.Interop"
mc:Ignorable="d"
Title="Moji Dict"
Background="Transparent"
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="CanResize"
interop:WindowBlur.IsEnabled="True">
<Window.Resources>
<local:SubtractValueConverter x:Key="SubtractValueConverter"/>
<Style x:Key="ModernScrollViewer" TargetType="{x:Type ScrollViewer}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<Grid>
<ScrollContentPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 添加TabControl样式 -->
<Style TargetType="TabControl">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
</Style>
<!-- 添加TabItem样式(删除重复的定义,只保留这一个) -->
<Style TargetType="TabItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="10,5"/>
<Setter Property="Foreground" Value="#CCCCCC"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="#999999"/>
<Setter Property="Background" Value="#303030"/> <!-- 将颜色改为更深的灰色 -->
</Trigger>
</Style.Triggers>
</Style>
<!-- 修改 RichTextBox 样式,移除错误的 TextWrapping 属性 -->
<Style TargetType="RichTextBox">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="#CCCCCC"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="FontFamily" Value="Microsoft YaHei"/>
<Setter Property="IsReadOnly" Value="True"/>
<Setter Property="AcceptsReturn" Value="True"/>
<Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<!-- 删除 TextWrapping 属性 -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RichTextBox">
<ScrollViewer x:Name="PART_ContentHost"
Focusable="False"
Background="Transparent"
Padding="{TemplateBinding Padding}"
BorderThickness="0"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<!-- 现在设置窗口属性 -->
<Window.Style>
<Style TargetType="Window">
<Setter Property="Title" Value="Moji Dict"/>
<Setter Property="Width" Value="700"/>
<Setter Property="Height" Value="{x:Static SystemParameters.PrimaryScreenHeight}"/>
<Setter Property="Left" Value="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth},
Converter={StaticResource SubtractValueConverter}, ConverterParameter=700}"/>
<Setter Property="Top" Value="0"/>
<Setter Property="Topmost" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="WindowStyle" Value="None"/>
</Style>
</Window.Style>
<WindowChrome.WindowChrome>
<WindowChrome
GlassFrameThickness="-1"
ResizeBorderThickness="5"
CaptionHeight="0"/>
</WindowChrome.WindowChrome>
<!-- 设置边框和阴影 -->
<!-- 窗口背景色,E0表示88%不透明度 -->
<Border CornerRadius="0"
Background="#D9202020"
Margin="0"
BorderBrush="{Binding BorderBrush}"
BorderThickness="0">
<Border.Effect>
<DropShadowEffect
BlurRadius="0"
ShadowDepth="0"
Opacity="0"/>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0"/> <!-- 顶部拖拽区域 -->
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- 顶部拖拽区域 - 透明但可拖拽 -->
<Rectangle Grid.Row="0" Fill="Transparent" MouseLeftButtonDown="DragWindow"/>
<!-- 内容区域:将 Margin 从 20,12,20,20 改为 10,6,10,10 -->
<Grid Grid.Row="1" Margin="6,3,6,6">
<TabControl x:Name="TabControl" Margin="5,5,5,5"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<TabItem Header="词汇">
<ScrollViewer Style="{StaticResource ModernScrollViewer}"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<RichTextBox x:Name="VocabularyTextBox"
IsReadOnly="True"
BorderThickness="0"
Background="Transparent"
HorizontalAlignment="Stretch"
MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl}, Path=ActualWidth}"
TextOptions.TextFormattingMode="Display"
CacheMode="BitmapCache">
<FlowDocument PageWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=RichTextBox}, Path=ActualWidth}"
LineHeight="1.5"
TextAlignment="Left">
<Paragraph/>
</FlowDocument>
</RichTextBox>
</ScrollViewer>
</TabItem>
<TabItem Header="例句">
<ScrollViewer Style="{StaticResource ModernScrollViewer}"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<RichTextBox x:Name="ExamplesTextBox"
IsReadOnly="True"
BorderThickness="0"
Background="Transparent"
HorizontalAlignment="Stretch"
MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl}, Path=ActualWidth}"
TextOptions.TextFormattingMode="Display"
CacheMode="BitmapCache">
<FlowDocument PageWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=RichTextBox}, Path=ActualWidth}"
LineHeight="1.5"
TextAlignment="Left">
<Paragraph/>
</FlowDocument>
</RichTextBox>
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
</Grid>
</Border>
</Window>