我知道這聽起來很奇怪,但它是真實的。綁定防止Visio事件發生
我有一個簡單的WPF應用程序,它承載了一個Visio控件。這沒有問題。一些重要的事件,如DocumentOpened確實有效。
但是,如果我想處理其他事件,例如BeforeShapeDeleted,CellChanged,它們會在將圖形綁定到DocumentOpened中的ListBox後停止觸發。
這裏是我的代碼:
public partial class MainWindow : Window { private AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl = new AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl(); public MainWindow() { InitializeComponent(); this.host.Child = this.visioControl; } private void Window_Loaded(object sender, 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); } void Application_CellChanged(Microsoft.Office.Interop.Visio.Cell Cell) { MessageBox.Show("Changed"); } void Application_BeforeShapeDelete(Microsoft.Office.Interop.Visio.Shape Shape) { MessageBox.Show("Deleted"); } void visioControl_DocumentOpened(object sender, AxMicrosoft.Office.Interop.VisOcx.EVisOcx_DocumentOpenedEvent e) { //if I comment the line bellow BeforeShapeDelete and CellChanged will work, if I leave it uncommented, they won't work... lstShapes.ItemsSource = this.visioControl.Window.Application.ActivePage.Shapes; } private void mnuOpen_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlgOpenDiagram = new Microsoft.Win32.OpenFileDialog(); if (dlgOpenDiagram.ShowDialog() == true) { this.visioControl.Src = dlgOpenDiagram.FileName; } } }
的問題在於,在界定的ItemsSource行DocumentOpened方法...
這是Visio 2007嗎? – gordatron