CameraView.xaml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <UserControl x:Class="LampInspectionMachine.Views.CameraView"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:LampInspectionMachine.Views"
  7. xmlns:Viewlocal="clr-namespace:LampInspectionMachine.ViewModels"
  8. xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
  9. xmlns:cognexWF1="clr-namespace:Cognex.VisionPro;assembly=Cognex.VisionPro.Controls"
  10. xmlns:prism="http://prismlibrary.com/"
  11. xmlns:valueConvert="clr-namespace:LampInspectionMachine.ValueConverters"
  12. prism:ViewModelLocator.AutoWireViewModel="True"
  13. xmlns:c="clr-namespace:LampInspectionMachine.ValueConverters"
  14. mc:Ignorable="d"
  15. FontFamily="微软雅黑"
  16. xmlns:lex="http://wpflocalizeextension.codeplex.com"
  17. lex:LocalizeDictionary.DesignCulture="zh-CN"
  18. lex:ResxLocalizationProvider.DefaultAssembly="LampInspectionMachine"
  19. lex:ResxLocalizationProvider.DefaultDictionary="Resources"
  20. FontSize="10"
  21. d:DesignHeight="800"
  22. d:DesignWidth="800"
  23. d:Background="White">
  24. <UserControl.Resources>
  25. <c:LanguageToResources x:Key="languageToResources" />
  26. <Style x:Key="buttonborder"
  27. TargetType="Border">
  28. <Setter Property="BorderThickness"
  29. Value="2" />
  30. <Setter Property="Background"
  31. Value="Transparent" />
  32. <Setter Property="VerticalAlignment"
  33. Value="Center" />
  34. <Setter Property="BorderBrush"
  35. Value="Transparent" />
  36. <Setter Property="CornerRadius"
  37. Value="5" />
  38. <Setter Property="Effect">
  39. <Setter.Value>
  40. <DropShadowEffect BlurRadius="10"
  41. Direction="1"
  42. ShadowDepth="0.5"
  43. Color="#2961AC" />
  44. </Setter.Value>
  45. </Setter>
  46. </Style>
  47. <Style TargetType="{x:Type TreeView}">
  48. <Setter Property="Background"
  49. Value="#F5F5F5" />
  50. <Setter Property="BorderBrush"
  51. Value="#CCCCCC" />
  52. <Setter Property="BorderThickness"
  53. Value="1" />
  54. <Setter Property="FontFamily"
  55. Value="Segoe UI" />
  56. <Setter Property="FontSize"
  57. Value="10" />
  58. <Setter Property="ItemContainerStyle">
  59. <Setter.Value>
  60. <Style TargetType="{x:Type TreeViewItem}">
  61. <Setter Property="Margin"
  62. Value="2" />
  63. <Setter Property="Padding"
  64. Value="5,3" />
  65. </Style>
  66. </Setter.Value>
  67. </Setter>
  68. </Style>
  69. <Style TargetType="{x:Type TreeViewItem}">
  70. <Setter Property="Template">
  71. <Setter.Value>
  72. <ControlTemplate TargetType="{x:Type TreeViewItem}">
  73. <StackPanel>
  74. <Grid>
  75. <Grid.ColumnDefinitions>
  76. <ColumnDefinition Width="Auto" />
  77. <ColumnDefinition Width="*" />
  78. </Grid.ColumnDefinitions>
  79. <Image Grid.Column="0"
  80. Source="/Resources/folder.png"
  81. Width="16"
  82. Height="16" />
  83. <ContentPresenter Grid.Column="1"
  84. ContentSource="Header" />
  85. </Grid>
  86. <ItemsPresenter />
  87. </StackPanel>
  88. </ControlTemplate>
  89. </Setter.Value>
  90. </Setter>
  91. <Setter Property="Foreground"
  92. Value="#333333" />
  93. <Style.Triggers>
  94. <Trigger Property="IsMouseOver"
  95. Value="True">
  96. <Setter Property="Background"
  97. Value="#E3F2FD" />
  98. <Setter Property="Foreground"
  99. Value="#0D47A1" />
  100. </Trigger>
  101. <Trigger Property="IsSelected"
  102. Value="True">
  103. <Setter Property="Background"
  104. Value="#BBDEFB" />
  105. <Setter Property="Foreground"
  106. Value="#0D47A1" />
  107. </Trigger>
  108. </Style.Triggers>
  109. </Style>
  110. <!--ComboBox-->
  111. <!--ComBoBox项选中背景色-->
  112. <SolidColorBrush x:Key="ComboBoxSelectdBackground"
  113. Color="#ff8c69" />
  114. <!--ComBoBox项鼠标经过背景色-->
  115. <SolidColorBrush x:Key="ComboBoxMouseOverBackground"
  116. Color="#ff3030" />
  117. <!--ComBoBox项选中前景色-->
  118. <SolidColorBrush x:Key="ComboBoxSelectedForeground"
  119. Color="White" />
  120. <!--ComBoBox项鼠标经过前景色-->
  121. <SolidColorBrush x:Key="ComboBoxMouseOverForegrond"
  122. Color="White" />
  123. <ControlTemplate x:Key="ComboBoxToggleButton"
  124. TargetType="{x:Type ToggleButton}">
  125. <Grid Height="25"
  126. HorizontalAlignment="Stretch">
  127. <Grid.ColumnDefinitions>
  128. <ColumnDefinition Width="*" />
  129. <ColumnDefinition Width="30" />
  130. </Grid.ColumnDefinitions>
  131. <Border Background="White"
  132. Grid.ColumnSpan="2"
  133. Opacity="0" />
  134. <Path x:Name="Arrow"
  135. Grid.Column="1"
  136. Data="M 0 0 6 6 12 0 Z"
  137. VerticalAlignment="Center"
  138. HorizontalAlignment="Center"
  139. Stretch="None"
  140. Fill="#999" />
  141. </Grid>
  142. <ControlTemplate.Triggers>
  143. <Trigger Property="IsChecked"
  144. Value="true">
  145. <Setter TargetName="Arrow"
  146. Property="RenderTransform">
  147. <Setter.Value>
  148. <RotateTransform CenterX="6"
  149. CenterY="3"
  150. Angle="180"></RotateTransform>
  151. </Setter.Value>
  152. </Setter>
  153. <Setter TargetName="Arrow"
  154. Property="Margin"
  155. Value="0 0 0 2" />
  156. </Trigger>
  157. </ControlTemplate.Triggers>
  158. </ControlTemplate>
  159. <Style TargetType="{x:Type ComboBox}">
  160. <Setter Property="ItemContainerStyle">
  161. <Setter.Value>
  162. <Style TargetType="ComboBoxItem">
  163. <Setter Property="Height"
  164. Value="20" />
  165. <Setter Property="Template">
  166. <Setter.Value>
  167. <ControlTemplate TargetType="{x:Type ComboBoxItem}">
  168. <Grid Height="{TemplateBinding Height}"
  169. Width="{TemplateBinding Width}">
  170. <Border x:Name="_borderbg"
  171. Background="Transparent" />
  172. <TextBlock Margin="3 0 3 0"
  173. VerticalAlignment="Center"
  174. x:Name="_txt"
  175. Foreground="#333"
  176. Text="{Binding Content,RelativeSource={RelativeSource TemplatedParent}}" />
  177. <Border x:Name="_border"
  178. Background="White"
  179. Opacity="0" />
  180. </Grid>
  181. <ControlTemplate.Triggers>
  182. <Trigger Property="IsSelected"
  183. Value="true">
  184. <Setter TargetName="_borderbg"
  185. Property="Background"
  186. Value="{StaticResource ComboBoxSelectdBackground}" />
  187. <Setter TargetName="_txt"
  188. Property="Foreground"
  189. Value="{StaticResource ComboBoxSelectedForeground}" />
  190. </Trigger>
  191. <MultiTrigger>
  192. <MultiTrigger.Conditions>
  193. <Condition Property="IsSelected"
  194. Value="false" />
  195. <Condition Property="IsMouseOver"
  196. Value="true" />
  197. </MultiTrigger.Conditions>
  198. <Setter TargetName="_borderbg"
  199. Property="Background"
  200. Value="{StaticResource ComboBoxMouseOverBackground}" />
  201. <Setter TargetName="_txt"
  202. Property="Foreground"
  203. Value="{StaticResource ComboBoxMouseOverForegrond}" />
  204. </MultiTrigger>
  205. </ControlTemplate.Triggers>
  206. </ControlTemplate>
  207. </Setter.Value>
  208. </Setter>
  209. </Style>
  210. </Setter.Value>
  211. </Setter>
  212. <Setter Property="Template">
  213. <Setter.Value>
  214. <ControlTemplate TargetType="{x:Type ComboBox}">
  215. <Grid>
  216. <Grid.ColumnDefinitions>
  217. <ColumnDefinition Width="0.7*" />
  218. <ColumnDefinition Width="0.3*"
  219. MaxWidth="30" />
  220. </Grid.ColumnDefinitions>
  221. <Border Grid.Column="0"
  222. Grid.ColumnSpan="2"
  223. BorderThickness="1"
  224. BorderBrush="{TemplateBinding BorderBrush}"
  225. CornerRadius="1,0,0,1" />
  226. <ContentPresenter HorizontalAlignment="Left"
  227. Margin="3,3,0,3"
  228. x:Name="ContentSite"
  229. VerticalAlignment="Center"
  230. Content="{TemplateBinding SelectionBoxItem}"
  231. ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
  232. ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
  233. IsHitTestVisible="False" />
  234. <!--ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen-->
  235. <ToggleButton Grid.Column="0"
  236. Grid.ColumnSpan="2"
  237. Template="{StaticResource ComboBoxToggleButton}"
  238. x:Name="ToggleButton"
  239. Focusable="false"
  240. IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
  241. ClickMode="Press" />
  242. <!--必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它-->
  243. <TextBox Visibility="Hidden"
  244. BorderThickness="0"
  245. Margin="2 0 0 0"
  246. x:Name="PART_EditableTextBox"
  247. VerticalAlignment="Center"
  248. Focusable="True"
  249. Background="Transparent"
  250. IsReadOnly="{TemplateBinding IsReadOnly}" />
  251. <!--Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen-->
  252. <Popup IsOpen="{TemplateBinding IsDropDownOpen}"
  253. Placement="Bottom"
  254. x:Name="Popup"
  255. Focusable="False"
  256. AllowsTransparency="True"
  257. PopupAnimation="Slide">
  258. <Grid MaxHeight="150"
  259. MinWidth="{TemplateBinding ActualWidth}"
  260. x:Name="DropDown"
  261. SnapsToDevicePixels="True">
  262. <Border x:Name="DropDownBorder"
  263. BorderBrush="#e8e8e8"
  264. BorderThickness="1 0 1 1" />
  265. <ScrollViewer Margin="1"
  266. SnapsToDevicePixels="True"
  267. HorizontalScrollBarVisibility="Auto"
  268. VerticalScrollBarVisibility="Auto"
  269. CanContentScroll="True">
  270. <!--StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True-->
  271. <StackPanel IsItemsHost="True"
  272. KeyboardNavigation.DirectionalNavigation="Contained"
  273. Background="White" />
  274. </ScrollViewer>
  275. </Grid>
  276. </Popup>
  277. </Grid>
  278. <ControlTemplate.Triggers>
  279. <Trigger Property="IsEditable"
  280. Value="true">
  281. <Setter TargetName="PART_EditableTextBox"
  282. Property="Visibility"
  283. Value="Visible" />
  284. </Trigger>
  285. </ControlTemplate.Triggers>
  286. </ControlTemplate>
  287. </Setter.Value>
  288. </Setter>
  289. </Style>
  290. <valueConvert:EnumToBoolConverter x:Key="EnumToBoolConverter" />
  291. </UserControl.Resources>
  292. <Grid>
  293. <Grid>
  294. <Grid.ColumnDefinitions>
  295. <ColumnDefinition Width="Auto" />
  296. <ColumnDefinition Width="*" />
  297. </Grid.ColumnDefinitions>
  298. <Grid>
  299. <StackPanel >
  300. <TextBlock Text="{Binding CanmeraName,Converter={StaticResource languageToResources}}" FontSize="20" VerticalAlignment="Center"/>
  301. <Grid>
  302. <Grid.RowDefinitions>
  303. <RowDefinition Height="Auto" />
  304. <RowDefinition Height="Auto" />
  305. <RowDefinition Height="Auto" />
  306. <RowDefinition Height="Auto" />
  307. <RowDefinition Height="Auto" />
  308. <RowDefinition Height="Auto" />
  309. </Grid.RowDefinitions>
  310. <StackPanel Grid.Row="0"
  311. Margin="50,15,0,0"
  312. Orientation="Vertical"
  313. VerticalAlignment="Center">
  314. <GroupBox Header="{lex:Loc 相机}">
  315. <ComboBox x:Name="combox"
  316. Width="190"
  317. Height="30"
  318. SelectedItem="{Binding Management.CurrCameraSn}"
  319. ItemsSource="{Binding Management.CameraList}" />
  320. </GroupBox>
  321. </StackPanel>
  322. <StackPanel Grid.Row="1"
  323. Margin="50,5,0,0"
  324. Orientation="Horizontal"
  325. VerticalAlignment="Center">
  326. <GroupBox Header="{lex:Loc 采集方式}">
  327. <StackPanel Orientation="Horizontal">
  328. <RadioButton Content="{lex:Loc 软触发}"
  329. IsChecked="{Binding Management.CurrCamConfig.TriggerMode,Converter={StaticResource EnumToBoolConverter},ConverterParameter=软触发}"
  330. GroupName="SoftTrigger"
  331. Margin="10" />
  332. <RadioButton Content="{lex:Loc 硬触发}"
  333. IsChecked="{Binding Management.CurrCamConfig.TriggerMode,Converter={StaticResource EnumToBoolConverter},ConverterParameter=硬触发}"
  334. GroupName="SoftTrigger"
  335. Margin="30,10,40,0" />
  336. </StackPanel>
  337. </GroupBox>
  338. </StackPanel>
  339. <StackPanel Grid.Row="2"
  340. Margin="50,5,0,0"
  341. Orientation="Horizontal"
  342. VerticalAlignment="Center">
  343. <GroupBox Header="{lex:Loc 曝光}">
  344. <StackPanel Orientation="Horizontal">
  345. <TextBox Width="190" Text="{Binding Management.CurrCamConfig.ExpouseTime}"/>
  346. <Border Background="#0A85D9"
  347. BorderBrush="Black"
  348. BorderThickness="1"
  349. Margin="10,5,3,5"
  350. CornerRadius="8">
  351. <Button Content="{lex:Loc 曝光写入}"
  352. Background="Transparent"
  353. Foreground="White"
  354. Margin="2"
  355. MinWidth="50"
  356. BorderThickness="0"
  357. Command="{Binding CameraExpouseTimeSetCommand}" />
  358. </Border>
  359. </StackPanel>
  360. </GroupBox>
  361. </StackPanel>
  362. <Border Grid.Row="3"
  363. BorderThickness="1"
  364. BorderBrush="#e8e8e8"
  365. Margin="50,10,0,0"
  366. Padding="5">
  367. <StackPanel Orientation="Horizontal"
  368. VerticalAlignment="Center">
  369. <Border Background="#0A85D9"
  370. BorderBrush="Black"
  371. BorderThickness="1"
  372. Margin="10,5,3,5"
  373. CornerRadius="8">
  374. <Button Content="{lex:Loc 初始化}"
  375. Background="Transparent"
  376. Foreground="White"
  377. Margin="2"
  378. MinWidth="50"
  379. BorderThickness="0"
  380. Command="{Binding CameraInifCommand}" />
  381. </Border>
  382. <Border Background="#0A85D9"
  383. BorderBrush="Black"
  384. BorderThickness="1"
  385. Margin="40,5,3,5"
  386. CornerRadius="8">
  387. <Button Content="{lex:Loc 关闭}"
  388. Background="Transparent"
  389. Foreground="White"
  390. Margin="2"
  391. MinWidth="50"
  392. BorderThickness="0"
  393. Command="{Binding CameraCloseCommand}"
  394. CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" />
  395. </Border>
  396. </StackPanel>
  397. </Border>
  398. <Border Grid.Row="4"
  399. BorderThickness="1"
  400. BorderBrush="#e8e8e8"
  401. Margin="50,10,0,0"
  402. Padding="5">
  403. <StackPanel Orientation="Horizontal"
  404. VerticalAlignment="Center">
  405. <Border Background="#0A85D9"
  406. BorderBrush="Black"
  407. BorderThickness="1"
  408. Margin="10,5,3,5"
  409. CornerRadius="8">
  410. <Button Content="{lex:Loc 开始采集}"
  411. Background="Transparent"
  412. Foreground="White"
  413. Margin="2"
  414. MinWidth="50"
  415. BorderThickness="0"
  416. Command="{Binding SoftTrigger_ContinueCommand}"
  417. CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" />
  418. </Border>
  419. <Border Background="#0A85D9"
  420. BorderBrush="Black"
  421. BorderThickness="1"
  422. Margin="40,5,3,5"
  423. CornerRadius="8">
  424. <Button Content="{lex:Loc 单张采集}"
  425. Background="Transparent"
  426. Foreground="White"
  427. Margin="2"
  428. MinWidth="50"
  429. BorderThickness="0"
  430. Command="{Binding SoftTriggerCommand}" />
  431. </Border>
  432. </StackPanel>
  433. </Border>
  434. <Border Grid.Row="5"
  435. BorderThickness="1"
  436. BorderBrush="#e8e8e8"
  437. Margin="50,10,0,0"
  438. Padding="5">
  439. <StackPanel Orientation="Horizontal"
  440. VerticalAlignment="Center">
  441. <Border Background="#0A85D9"
  442. BorderBrush="Black"
  443. BorderThickness="1"
  444. Margin="10,5,3,5"
  445. CornerRadius="8">
  446. <Button Content="{lex:Loc 图片轮询}"
  447. Background="Transparent"
  448. Foreground="White"
  449. Margin="2"
  450. MinWidth="50"
  451. BorderThickness="0"
  452. Command="{Binding ImageTrigger_ContinueCommand}"
  453. CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" />
  454. </Border>
  455. <Border Background="#0A85D9"
  456. BorderBrush="Black"
  457. BorderThickness="1"
  458. Margin="40,5,3,5"
  459. CornerRadius="8">
  460. <Button Content="{lex:Loc 单张图片}"
  461. Background="Transparent"
  462. Foreground="White"
  463. Margin="2"
  464. MinWidth="50"
  465. BorderThickness="0"
  466. Command="{Binding ImageTriggerCommand}" />
  467. </Border>
  468. </StackPanel>
  469. </Border>
  470. </Grid>
  471. </StackPanel>
  472. </Grid>
  473. <Grid Grid.Column="1">
  474. <Grid.RowDefinitions>
  475. <RowDefinition/>
  476. <RowDefinition Height="180"/>
  477. </Grid.RowDefinitions>
  478. <DockPanel Margin="20,20,10,20" Grid.Row="0">
  479. <WindowsFormsHost Viewlocal:CogDisplayBinder.ImageSource="{Binding Management.Render}">
  480. <cognexWF1:CogRecordDisplay x:Name="cogRecordDisplay" />
  481. </WindowsFormsHost>
  482. </DockPanel>
  483. <DockPanel Grid.Row="1">
  484. <ListBox ItemsSource="{Binding Logs}"
  485. BorderBrush="Transparent">
  486. <i:Interaction.Behaviors>
  487. <Viewlocal:AutoScrollBehavior />
  488. </i:Interaction.Behaviors>
  489. </ListBox>
  490. </DockPanel>
  491. </Grid>
  492. </Grid>
  493. </Grid>
  494. </UserControl>