CameraView.xaml 23 KB

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