Frage

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?

War es hilfreich?

Lösung 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.

Andere Tipps

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;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top