Posted 13 years ago by Robert Croshere
Version: 11.1.0113
Avatar
Hi,

When a context menu is placed in the resources part as follows:

    <UserControl.Resources>
        <shared:ContextMenu
            x:Key="menu">
            <shared:MenuItem
                Header="contexttest" />
        </shared:ContextMenu>
    </UserControl.Resources>
And referred to like this:

shared:ContextMenuService.ContextMenu="{StaticResource menu}"
Every time the contextmenu is invoked, an exception will occur that will crash the app with the following details:

An unhandled exception ('Unhandled error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.ArgumentException: Value does not fall within the expected range.

If the contextmenu is placed directly within the control (thus not using a static resource) it works as expected. However, I'm using the context menu in a DataTemplate for a listbox that can contain many items and I don't want the contextmenu to be created for each item, thats why I'm using a static resource.

Regards,
Robert Croshere

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Robert,

The ContextMenu is a visual and therefore can only have 1 parent. So unfortunately, you cannot reuse it like you show above.


Actipro Software Support

Posted 13 years ago by Robert Croshere
Avatar
Ok,

I guess I would have expected a different error message. Might be a good idea to state that in de documentation as it differs from how WPF works (and they are meant to be similar).

thanks,
Robert
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Robert,

Silverlight is notoriously bad at providing useful error messages. We've updated our documentation to indicate that the ContextMenu cannot be reused.


Actipro Software Support

The latest build of this product (v18.1 build 0233) was released 4 years ago, which was after the last post in this thread.