【发布时间】:2011-11-12 03:57:56
【问题描述】:
我知道这听起来很奇怪,但这是真的。
我有一个托管 Visio 控件的简单 WPF 应用程序。没有问题。一些重要的事件,例如 DocumentOpened 确实有效。
但如果我想处理其他事件,例如 BeforeShapeDeleted、CellChanged,一旦我将 Shapes 绑定到 DocumentOpened 中的 ListBox,它们就会停止触发。
这是我的代码:
公共部分类 MainWindow : 窗口 { 私有 AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl = new AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl(); 公共主窗口() { 初始化组件(); this.host.Child = this.visioControl; } 私人无效Window_Loaded(对象发送者,RoutedEventArgs e) { this.visioControl.DocumentOpened += new AxMicrosoft.Office.Interop.VisOcx.EVisOcx_DocumentOpenedEventHandler(visioControl_DocumentOpened); this.visioControl.Window.Application.BeforeShapeDelete += new Microsoft.Office.Interop.Visio.EApplication_BeforeShapeDeleteEventHandler(Application_BeforeShapeDelete); this.visioControl.Window.Application.CellChanged += new Microsoft.Office.Interop.Visio.EApplication_CellChangedEventHandler(Application_CellChanged); } 无效 Application_CellChanged(Microsoft.Office.Interop.Visio.Cell 单元) { MessageBox.Show("改变"); } 无效 Application_BeforeShapeDelete(Microsoft.Office.Interop.Visio.Shape 形状) { MessageBox.Show("已删除"); } void visioControl_DocumentOpened(对象发送者,AxMicrosoft.Office.Interop.VisOcx.EVisOcx_DocumentOpenedEvent e) { //如果我注释下面的行,BeforeShapeDelete 和 CellChanged 将起作用,如果我不注释它,它们将不起作用... lstShapes.ItemsSource = this.visioControl.Window.Application.ActivePage.Shapes; } private void mnuOpen_Click(对象发送者,RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlgOpenDiagram = new Microsoft.Win32.OpenFileDialog(); if (dlgOpenDiagram.ShowDialog() == true) { this.visioControl.Src = dlgOpenDiagram.FileName; } } }问题在于定义 ItemsSource 的行中的 DocumentOpened 方法...
【问题讨论】:
标签: .net wpf activex vsto visio