WPF绑定防止Visio事件被触发 [英] WPF Binding Prevents Visio Events from Firing
问题描述
我知道这听起来很奇怪,但确实如此。
I know this sounds bizarre, but it is true.
我有一个简单的WPF应用程序托管一个Visio控件。没有问题。一些基本事件,例如DocumentOpened确实有效。
I have a simply WPF application that hosts a Visio control. There are no problems with that. Some essential events, such as DocumentOpened does work.
但是如果我想处理其他事件,例如,BeforeShapeDeleted,CellChanged,一旦我将Shapes绑定到DocumentOpened中的ListBox,它们就会停止触发。
But if I want to handle other events, for instance, BeforeShapeDeleted, CellChanged, they stop firing once I bind Shapes to a ListBox in the DocumentOpened.
这是我的代码:
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;
}
}
}
推荐答案
嗨Mike,
感谢您发帖。
阅读完您的帖子后,我尝试重现该方案,但失败了。那么,您能否告诉我关于您的WPF项目的可重现步骤?你是如何添加AxDrawingControl的,我无法通过从
COM Components选项卡中选择项目从ToolBox中找到它。
After reading your post, I tried to reproduce the scenario on my side, but failed. So, could you tell me the reproducible steps about your WPF project? How did you add the AxDrawingControl , I can't find it from the ToolBox by choosing the item from the COM Components tab.
如果你能发给我,那就太好了您的项目副本到我的电子邮箱
v-bpeng@microsoft.com
It will be nice if you can send me a copy of your project to my email v-bpeng@microsoft.com
我将根据您的详细信息进一步研究。
I will do further research with your detailed information.
最好的问候,
这篇关于WPF绑定防止Visio事件被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!