سؤال

DotNet 4.0 throws a runtime ComException when a MenuItem, which was previously visible, becomes hidden. When switching to DotNet 3.5 the Exception is no longer thrown.

Setup

  • Create new WPF DotNet 4.0 project
  • Add the following XAML code to the default Grid

    <Menu Height="23"> <MenuItem Header="Item1"> <MenuItem Header="SubItem1"/> </MenuItem> <MenuItem Header="Item2"> <MenuItem Header="SubItem2" /> </MenuItem> </Menu>

  • Make sure that "Common Language Runtime Exceptions" is checked under Debug->Exceptions

  • Run the application and click on the first menu item, then click on the second menu item, then move the mouse pointer back to the first menu item

Does anyone know of a specific way to workaround this problem?

هل كانت مفيدة؟

المحلول 2

A set of Windows 7 update fixed this problem. Bizarre!

I have been running windows 7 (64bit) without updates for approximately 1 year now. After applying a large set of cumulative updates the problem went away.

نصائح أخرى

By invoking the relevant controls from code, before the user has a chance to do so from the GUI, prevents the UI Automation exception for being thrown. Why?

e.g.

i1.IsSubmenuOpen = false;
i2.IsSubmenuOpen = true;
i2.IsSubmenuOpen = false;
i1.IsSubmenuOpen = true;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top