ToolBlockEdit.xaml.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Cognex.VisionPro;
  2. using Cognex.VisionPro.ToolBlock;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using System.Windows.Threading;
  18. namespace Plugins.Vpp.Views
  19. {
  20. /// <summary>
  21. /// ToolBlockEdit.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class ToolBlockEdit : UserControl
  24. {
  25. public CogToolBlockEditV2 CogToolBlockEdit
  26. {
  27. get => ICogToolBlockEdit;
  28. set => ICogToolBlockEdit = value;
  29. }
  30. public ToolBlockEdit()
  31. {
  32. InitializeComponent();
  33. Init();
  34. }
  35. public void Init()
  36. {
  37. try
  38. {
  39. var type = ICogToolBlockEdit.GetType();
  40. var property = type.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
  41. if (property != null)
  42. {
  43. property.SetValue(ICogToolBlockEdit, true, null);
  44. }
  45. // 渲染引擎修复:编辑器内部各工具的显示面板是动态创建的 Cog 显示控件,
  46. // 统一切 GDI 渲染引擎(硬件加速渲染在向日葵远程/部分驱动环境整块白屏)。
  47. // 编辑器加载工具/双击工具都会新面板 —— 用短周期定时器重扫一段时间兜底。
  48. CogGdiRender.Apply(ICogToolBlockEdit);
  49. var rescan = new System.Windows.Threading.DispatcherTimer { Interval = TimeSpan.FromMilliseconds(600) };
  50. int ticks = 0;
  51. rescan.Tick += (s, e) =>
  52. {
  53. try { CogGdiRender.Apply(ICogToolBlockEdit); }
  54. catch { }
  55. if (++ticks > 40) rescan.Stop();
  56. };
  57. rescan.Start();
  58. WFH.Child = ICogToolBlockEdit;
  59. WFH.Child = ICogToolBlockEdit;
  60. ICogToolBlockEdit.BackColor = Color.Black;
  61. //Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle,
  62. // new Action(() => IsOpen = true));
  63. }
  64. catch (Exception ex)
  65. {
  66. }
  67. }
  68. }
  69. }