using Cognex.VisionPro; using Cognex.VisionPro.ToolBlock; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; namespace Plugins.Vpp.Views { /// /// ToolBlockEdit.xaml 的交互逻辑 /// public partial class ToolBlockEdit : UserControl { public CogToolBlockEditV2 CogToolBlockEdit { get => ICogToolBlockEdit; set => ICogToolBlockEdit = value; } public ToolBlockEdit() { InitializeComponent(); Init(); } public void Init() { try { var type = ICogToolBlockEdit.GetType(); var property = type.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); if (property != null) { property.SetValue(ICogToolBlockEdit, true, null); } // 渲染引擎修复:编辑器内部各工具的显示面板是动态创建的 Cog 显示控件, // 统一切 GDI 渲染引擎(硬件加速渲染在向日葵远程/部分驱动环境整块白屏)。 // 编辑器加载工具/双击工具都会新面板 —— 用短周期定时器重扫一段时间兜底。 CogGdiRender.Apply(ICogToolBlockEdit); var rescan = new System.Windows.Threading.DispatcherTimer { Interval = TimeSpan.FromMilliseconds(600) }; int ticks = 0; rescan.Tick += (s, e) => { try { CogGdiRender.Apply(ICogToolBlockEdit); } catch { } if (++ticks > 40) rescan.Stop(); }; rescan.Start(); WFH.Child = ICogToolBlockEdit; WFH.Child = ICogToolBlockEdit; ICogToolBlockEdit.BackColor = Color.Black; //Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, // new Action(() => IsOpen = true)); } catch (Exception ex) { } } } }