WPF_MaterialTemplate.xaml
23.8 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<UserControl x:Class="SmartScan.SetControl.WPF.WPF_MaterialTemplate"
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:SmartScan.SetControl.WPF" xmlns:wfh="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns:local1="clr-namespace:SmartScan.SetControl.WPF.Convent"
mc:Ignorable="d"
d:DesignHeight="700" d:DesignWidth="1200" Background="#FF111111" BorderBrush="#FF0066CC" Loaded="UserControl_Loaded">
<UserControl.Resources>
<local1:OcrTextHighlighterConverter x:Key="OcrTextHighlighter"/>
<local1:WidthMinusMarginConverter x:Key="WidthMinusMarginConverter"/>
<!-- 菜单按钮样式 - 包含底部边框作为分隔线 -->
<Style x:Key="MenuButtonStyle" TargetType="Button">
<Setter Property="Background" Value="#FF111111"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Height" Value="auto"/>
<Setter Property="Margin" Value="0,15,0,0"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Width" Value="120"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="BorderThickness" Value="0,0,0,0"/>
<Setter Property="BorderBrush" Value="#5a5a5a"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="0,0,0,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- 图标容器 -->
<Border Grid.Row="0">
<ContentPresenter x:Name="Icon" Height="34" HorizontalAlignment="Center" Content="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
</Border>
<!-- 文字容器 -->
<Viewbox Grid.Row="1" Stretch="Uniform" MaxWidth="{TemplateBinding Width}" MaxHeight="13">
<TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Center"
VerticalAlignment="Center" Margin="0,0,0,0"
FontSize="12" Foreground="{TemplateBinding Foreground}" FontFamily="微软雅黑"/>
</Viewbox>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#252525"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#2d2d2d"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="250" />
</Grid.ColumnDefinitions>
<!-- 左侧模板列表 -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<!-- 标题 -->
<Border Grid.Row="0" BorderThickness="0,0,1,1" BorderBrush="#333333">
<TextBlock Text="模板" FontSize="14" FontFamily="微软雅黑" Name="FrmSet_BtnMaterial" HorizontalAlignment="Center" Foreground="White" Padding="10,5" />
</Border>
<!-- 模板列表 -->
<ListView x:Name="data1" Grid.Row="1" Background="#1c1c1c" BorderThickness="1" BorderBrush="Gray" Foreground="White" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="data1_SelectionChanged">
<!-- 设置交替行数为2 -->
<ListView.AlternationCount>2</ListView.AlternationCount>
<!-- 自定义每个项的显示模板 -->
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="14" FontFamily="微软雅黑"
Foreground="White"
TextAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Padding" Value="5,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderThickness="0">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="#005A9E"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- 交替行颜色 -->
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#353535"/>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#2a2a2a"/>
</Trigger>
<!-- 选中行颜色 -->
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#0061c8"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
<!-- 鼠标悬停效果 -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#464646"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
<!-- 底部按钮 -->
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" HorizontalAlignment="Center">
<Button Content="新建" FontSize="14" FontFamily="微软雅黑" x:Name="UsrMaterialTemplate_BtnAddMate" Width="60" Style="{StaticResource MenuButtonStyle}" Click="BtnAddMate_Click">
<Button.Tag>
<Path Data="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" Fill="White" Width="20" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Center">
<Button Content="重命名" FontSize="14" FontFamily="微软雅黑" x:Name="UsrMaterialTemplate_BtnRenameMate" Width="60" Style="{StaticResource MenuButtonStyle}" Click="BtnRenameMate_Click">
<Button.Tag>
<Path Data="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z" Fill="White" Width="20" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="2" HorizontalAlignment="Center">
<Button Content="删除" x:Name="UsrMaterialTemplate_BtnDelMate" Width="60" Style="{StaticResource MenuButtonStyle}" Click="BtnDelMate_Click">
<Button.Tag>
<Path Width="20" Data="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" Fill="White" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
<Border Grid.Column="3" BorderThickness="0,0,1,0" BorderBrush="#333333" HorizontalAlignment="Right"></Border>
</Grid>
</Grid>
<!-- 中间图像显示区域 -->
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<!-- 标题 -->
<Border Grid.Row="0" BorderThickness="0,0,1,1" BorderBrush="#333333">
<TextBlock Text="图片" FontSize="14" FontFamily="微软雅黑" Name="UsrMaterialTemplate_pnlImg" Foreground="White" Padding="10,5" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<!-- 图像区域 -->
<Border Grid.Row="1" BorderThickness="0,0,1,1" BorderBrush="#333333">
<Grid>
<wfh:WindowsFormsHost Name="imageViewer" Background="Aqua"></wfh:WindowsFormsHost>
</Grid>
</Border>
<!-- 缩放状态栏 -->
<Grid Grid.Row="2" Visibility="Collapsed" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="16%" Foreground="White" Margin="10,5" />
<StackPanel Grid.Column="2" Orientation="Horizontal" Margin="0,0,10,0">
<Button Content="−" Width="25" Height="25" Background="Transparent" Foreground="White" BorderThickness="1" BorderBrush="#444" Margin="2" />
<Button Content="+" Width="25" Height="25" Background="Transparent" Foreground="White" BorderThickness="1" BorderBrush="#444" Margin="2" />
<Button Width="25" Height="25" Background="Transparent" BorderThickness="1" BorderBrush="#444" Margin="2">
<Viewbox Width="12" Height="12">
<Canvas Width="24" Height="24">
<Path Data="M3,3H21V21H3V3M7,7V9H9V7H7M11,7V9H13V7H11M15,7V9H17V7H15M7,11V13H9V11H7M11,11V13H13V11H11M15,11V13H17V11H15M7,15V17H9V15H7M11,15V17H13V15H11M15,15V17H17V15H15Z" Fill="White" />
</Canvas>
</Viewbox>
</Button>
</StackPanel>
</Grid>
<!-- 底部工具栏 -->
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" HorizontalAlignment="Center">
<Button Content="打开光源" x:Name="UsrCamera_BtnOpenLight" Style="{StaticResource MenuButtonStyle}" Click="BtnOpenLight_Click">
<Button.Tag>
<Path Data="M7,2V13H10V22L17,10H13L17,2H7Z" Width="20" Height="20" Fill="Orange" Stretch="Uniform" />
</Button.Tag>
</Button>
<!--<Button Width="30" Height="30" Background="Transparent" BorderBrush="Transparent" Name="BtnOpenLight" Click="BtnOpenLight_Click">
<Path Data="M7,2V13H10V22L17,10H13L17,2H7Z" Fill="Orange" Stretch="Uniform" />
</Button>
<TextBlock Text="打开光源" Name="UsrMaterialTemplate_BtnOpenLight" Foreground="White" HorizontalAlignment="Center" Margin="0,2,0,0" />-->
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Center">
<Button Content="关闭光源" x:Name="UsrMaterialTemplate_BtnCloseLight" Style="{StaticResource MenuButtonStyle}" Click="BtnCloseLight_Click">
<Button.Tag>
<Path Data="M7,2V13H10V22L17,10H13L17,2H7Z" Fill="LightGray" Width="20" Height="20" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="2" HorizontalAlignment="Center">
<Button Content="打开" x:Name="UsrMaterialTemplate_BtnLocalImage" Style="{StaticResource MenuButtonStyle}" Click="UsrMaterialTemplate_BtnLocalImage_Click">
<Button.Tag>
<Path Data="M19,20H4C2.89,20 2,19.1 2,18V6C2,4.89 2.89,4 4,4H10L12,6H19A2,2 0 0,1 21,8V18A2,2 0 0,1 19,20Z" Fill="Yellow" Width="20" Height="20" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="3" HorizontalAlignment="Center">
<Button Content="保存" x:Name="UsrMaterialTemplate_BtnSaveImage" Style="{StaticResource MenuButtonStyle}" Click="UsrMaterialTemplate_BtnSaveImage_Click">
<Button.Tag>
<Path Data="M15,9H5V5H15M12,19A3,3 0 0,1 9,16A3,3 0 0,1 12,13A3,3 0 0,1 15,16A3,3 0 0,1 12,19M17,3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V7L17,3Z" Width="20" Height="20" Fill="White" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="4" HorizontalAlignment="Center" >
<Button Content="获取图像" FontSize="23" x:Name="UsrMaterialTemplate_BtnCameraImage" Style="{StaticResource MenuButtonStyle}" Click="UsrMaterialTemplate_BtnCameraImage_Click">
<Button.Tag>
<Path Data="M20,4H16.83L15,2H9L7.17,4H4A2,2 0 0,0 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V6A2,2 0 0,0 20,4M20,18H4V6H8.05L9.88,4H14.12L15.95,6H20V18M12,7A5,5 0 0,0 7,12A5,5 0 0,0 12,17A5,5 0 0,0 17,12A5,5 0 0,0 12,7M12,15A3,3 0 0,1 9,12A3,3 0 0,1 12,9A3,3 0 0,1 15,12A3,3 0 0,1 12,15Z" Fill="White" Width="20" Height="20" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="5" HorizontalAlignment="Center">
<Button Content="条码" x:Name="UsrMaterialTemplate_BtnScanCode" Style="{StaticResource MenuButtonStyle}" Click="UsrMaterialTemplate_BtnScanCode_Click">
<Button.Tag>
<Path Data="M2,6H4V18H2V6M5,6H6V18H5V6M7,6H10V18H7V6M11,6H12V18H11V6M14,6H16V18H14V6M17,6H20V18H17V6M21,6H22V18H21V6Z" Width="20" Height="20"
Fill="White" Stretch="Fill" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="6" HorizontalAlignment="Center" >
<Button Content="OCR" x:Name="UsrMaterialTemplate_BtnOcrCode" Style="{StaticResource MenuButtonStyle}" Click="UsrMaterialTemplate_BtnOcrCode_Click">
<Button.Tag>
<Path Data="M20,20H4A2,2 0 0,1 2,18V6A2,2 0 0,1 4,4H20A2,2 0 0,1 22,6V18A2,2 0 0,1 20,20M4,6V18H20V6H4M6,9H18V11H6V9M6,13H16V15H6V13Z"
Fill="White" Height="20" Stretch="Uniform" Width="20" />
</Button.Tag>
</Button>
</StackPanel>
</Grid>
</Grid>
<!-- 右侧OCR结果区域 -->
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<!-- 标题行 -->
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="#333333">
<TextBlock Text="条码" FontSize="14" FontFamily="微软雅黑" Name="UsrMaterialTemplate_pnlCode" Foreground="White" Padding="10,5" HorizontalAlignment="Center"/>
</Border>
<Grid Grid.Row="1">
<ListView x:Name="data3" Background="#1c1c1c" BorderThickness="1" BorderBrush="Gray" Foreground="White" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="data3_SelectionChanged">
<!-- 设置交替行数为2 -->
<ListView.AlternationCount>2</ListView.AlternationCount>
<!-- 自定义每个项的显示模板 -->
<ListView.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding Converter={StaticResource OcrTextHighlighter}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" FontSize="14" FontFamily="微软雅黑"
Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Converter={StaticResource WidthMinusMarginConverter}}"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="MinHeight" Value="25"/>
<Setter Property="Padding" Value="5,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderThickness="0">
<ContentPresenter HorizontalAlignment="Left"
VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="#005A9E"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- 交替行颜色 -->
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#353535"/>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#2a2a2a"/>
</Trigger>
<!-- 选中行颜色 -->
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#0061c8"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
<!-- 鼠标悬停效果 -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#464646"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
<!-- 底部工具栏 -->
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="1,0,0,0" BorderBrush="#333333" HorizontalAlignment="Left"></Border>
<StackPanel Grid.Column="1" HorizontalAlignment="Center">
<Button Content="提取" x:Name="UsrMaterialTemplate_BtnExtractCode" Style="{StaticResource MenuButtonStyle}" Click="UsrMaterialTemplate_BtnExtractCode_Click">
<Button.Tag>
<Ellipse Width="20" Height="20" Stroke="White" StrokeThickness="2" />
</Button.Tag>
</Button>
</StackPanel>
<StackPanel Grid.Column="2" HorizontalAlignment="Center">
<Button Content="验证" x:Name="UsrMaterialTemplate_BtnTemplateValite" Style="{StaticResource MenuButtonStyle}" Click="UsrMaterialTemplate_BtnTemplateValite_Click">
<Button.Tag>
<Path Data="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" Fill="White" Width="20" Height="20" Stretch="Uniform" />
</Button.Tag>
</Button>
</StackPanel>
</Grid>
</Grid>
</Grid>
</UserControl>