CameraView.xaml 26 KB

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