Problems with ApplicationMenu.ItemsSource binding

Ribbon for WPF Forum

Posted 11 years ago by Phil Devaney
Version: 13.2.0590
Platform: .NET 4.5
Environment: Windows 7 (64-bit)

We've been using data binding/templates for context menus for some time quite successfully (with a bit of help from you in the beginning). Basically we have a MenuViewModel & related classes that expose Command, Label, ImageSourceLarge etc properties, and a set of styles & data templates that create ribbon Buttons, PopupButtons & Menus from them.

We have just tried applying this approach to the application menu to allow different apps to extend our "application framework" shell more easily. I had to use a different set of templates with VariantSize="Large" but everything else is the same as context menus. Everything mostly works apart from two problems:

1. The 'Add to QAT' menu item is missing from the context menu on the items in the application menu

2. The items in the application menu are no longer visible to UI automation. This is quite serious for us as we used CodedUI tests extensively, and the first thing most tests do is 'File/New' or 'File/Open'! We are setting the AutomationId in our style, but when using the MS 'Inspect Object' tool we can't see any controls below the application menu control (i.e. the individual buttons). For normal context menus using this technique, the buttons appear to Inspect OK.

I will send a sample to the support address demoing the problem.

Comments (3)

Posted 11 years ago by Phil Devaney

We've done a bit more investigation and tracked the source of problem 2 down to ApplicationMenuAutomationPeer. It looks like GetChildrenCore just iterates around the Items collection and tries to cast to UIElement, but in this scenario the Items collection contains VM objects and the MenuItems are created by the ItemContainerGenerator. Looking at the implementation of System.Windows.Automation.Peers.UIElementAutomationPeer, it actually uses VisualTreeHelper to walk the tree instead of using Items.

We have a workaround by creating derived classes from ApplicationMenu & ApplicationMenuAutomationPeer and walking the visual tree to create the child peers. This doesn't fix the QAT problem, but I would guess maybe something somewhere is doing a similar UIElement cast.

Posted 11 years ago by Phil Devaney

A bit more information on the 'Add to QAT' problem. I added a handler for ContextMenuOpening on the MainWindow in my sample app. When the handler is called for the working ribbon, e.Source is the Button element, but for the non-working ribbon it is the ApplicationMenu element. In both cases e.OriginalSource is the Border or Run from the Button's template depending on where I click.

Hope this helps.

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA

Thanks for the sample Phil.  We've resolved these issues for the next maintenance release.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.