CameraView.xaml 23 KB

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