We have a problem with a context menu, which is created and filled exclusively in code. Sometimes, the whole application crashes when the context menu is about to be displayed. Often the error can't be tracked as the application crashes completely. However sometimes we can track an error message which I think is related to the issue:
bei MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
bei MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
bei MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)
bei System.Windows.Controls.Control.ApplyTemplate()
bei Telerik.Windows.Controls.RadMenuItem.ChangeTemplate(MenuItemRole role)
bei Telerik.Windows.Controls.RadMenuItem.UpdateRole()
bei Telerik.Windows.Controls.RadMenuItem.OnLoaded(Object sender, RoutedEventArgs e)
bei MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
bei MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Failed to assign to property 'System.Windows.Controls.ContentPresenter.Content'. [Line: 476 Position: 83]
I believe that it hast to do with initializing the context menu because once the menu has been opened the error will not appear anymore. But most of the time it workes so it is hard to reproduce the error (It always works when I step thorough the code in debug mode).
Could you give us any hints what could be the matter?
Thanks a lot
Volkmar
7 Answers, 1 is accepted
We are not aware of such an error and we are not able to reproduce the bad behavior. Could you please send us a sample code or project where the error can be reproduced. Also could you please tell us if you are using SL4 or SL5 binaries.
Regards,
Boyan
the Telerik team

Line: 453
Error: Sys.InvalidOperationException: Invalid XAML for control 'MMSMSL'. [] (line 512, col 65): Failed to assign to property 'System.Windows.Controls.ContentPresenter.Content'.

Create your RadMenu object with a dummy-item (inclusive all submenus).
After that add the RadMenuItems you need and remove the dummy finally.
It works for me. Hope this helps!

Thanks, Jordan

please take a look at the following thread. I think the reason for this error is the same or at least a similar one as described in the othert thread.
http://www.telerik.com/community/forums/silverlight/richtextbox/problem-with-image-inside-richtextbox.aspx
IMHO the problem has nothing to do with user defined context menus because the integrated context menus in RadRichTextBox (at least the image context menus) are throwing the same exception.
We reproduced the problem, thanks to Ender and after some investigation we found that there is a bug in Silverlight 4 when control templates are changed and there are visual elements in the Header. The bug is fixed in SL5 and that is why it is working as expected there.
If you don't want to upgrade to Silverlight 5, we found a workaround that will work in Silverlight 4 as well. You can use DataItems instead of RadMenuItems and it will work as expected.
You can find attached the sample project that Ender send us with the workaround applied.
Kind regards,
Boyan
the Telerik team

Jordan