Hi,
I am using the RadContextMenu to show the "Close" option, when I right click on the RadContextMenuItem. I am facing the following problem when I use the context menu to close the RadTileViewItem for the second time.
Menu.GetClickedElement<RadTileViewItem>()' threw an exception of type 'System.ArgumentException' Telerik.Windows.Controls.RadTileViewItem {System.ArgumentException}
Following is the code which I am using for this.
<telerikNavigation:RadContextMenu.ContextMenu> <telerikNavigation:RadContextMenu x:Name="RadTileViewContextMenu" Height="40" Width="120" ItemClick="ContextMenu_ItemClick"> <telerikNavigation:RadMenuItem Header="Close"></telerikNavigation:RadMenuItem>
</telerikNavigation:RadContextMenu>
</telerikNavigation:RadContextMenu.ContextMenu>
private
void ContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
RadContextMenu Menu = sender as RadContextMenu;
if (Menu.GetClickedElement<RadTileViewItem>() != null)
{
RadTileViewItem ClickedItem = Menu.GetClickedElement<RadTileViewItem>() as RadTileViewItem;
MDIMainTile.Items.Remove(ClickedItem);
}
}
}
Following is the Scenario where I am getting the error.
Lets think we have 3 Tileviews, out of one is Maximized and other 2 are minimized. Right click on the Maximized Item and choose the close option from contextMenu. It will close properly and another Item will be Maximized automatically. Now again Right click on the Item which is maximized and select the close option. In this case I am facing the above mentioned error for Menu.GetClickedElement<RadTileViewItem>() .
Please suugest.
Regards,
SivaPrasad.B
14 Answers, 1 is accepted
I wasn't able to reproduce your problem, so could you please examine the attached project and if you still have that issue please send us some more code?
All the best,Hello there,
Could you please add a workaround for invisible controls to the beginning of the ApplicationHelper.TransformToScreenRoot().
Something like this:
#if SILVERLIGHT
if (!RootVisual.IsAncestorOf(target)) // Invisible
{
return ...
}
var generalTransform = target.TransformToVisual(null);
....
Thanks
The ApplicationHelper class is an internal class and as such is created for internal use only. Therefore we're not planning to modify it.
Best wishes,
Tina Stancheva
the Telerik team
The implementation of this method assumes that the 'target' is always in the visual tree. This is wrong assumption (if an element is not in the visual tree, you cannot call TransformToVisual on it) and very likely source of the error mentioned in the original post.
Regards
The TransformToScreenRoot() method cannot transform to ScreenRoot target that isn't a part of the visual tree. Also, we couldn't reproduce the issue originally raised in this thread on our side and if you can reproduce it, we would highly appreciate it if you can send us a sample project illustrating a scenario where the issue is reproduced and where the target of the TransformToScreenRoot() method isn't a part of the visual tree. Also, can you elaborate on what you expect the TransformToScreenRoot() method to return for such controls?
All the best,
Tina Stancheva
the Telerik team
When the RadContextMenu.GetClickedElement<>() method is called the following exception is thrown:
System.ArgumentException: Value does not fall within the expected
range.
Here is the stack trace:
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name,
CValue[] cvData)
at MS.Internal.XcpImports.MethodPack(IntPtr
objectPtr, String methodName, Object[] rawData)
at
MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement
visual)
at System.Windows.UIElement.TransformToVisual(UIElement
visual)
at
Telerik.Windows.Controls.ApplicationHelper.TransformToScreenRoot(UIElement
target)
at
Telerik.Windows.Controls.VisualTreeHelperExtensions.GetElementsInHostCoordinates[T](UIElement
subtree, Point position)
at
Telerik.Windows.Controls.VisualTreeHelperExtensions.GetElementsInScreenCoordinates[T](Point
mousePosition, FrameworkElement rootVisual)
at
Telerik.Windows.Controls.VisualTreeHelperExtensions.GetElementsInScreenCoordinates[T](FrameworkElement
relativeTo, Point mousePosition)
at
Telerik.Windows.Controls.RadContextMenu.GetClickedElement[T]()
It happens when the control, to which the context menu is linked, is not in the visual tree. There are workarounds for this, but frankly the simplest way is to fix it in the ApplicationHelper.TransformToScreenRoot() method.
Regards
First of all accept my apology for the delayed response. We will definitely look into this and I will keep you posted.
Greetings,
Tina Stancheva
the Telerik team
Can you please test your projects against the Q3 SP1 official release (version 2010.3.1314) and let us know if you still experience any issues?
Thank you in advance.
Greetings,
Tina Stancheva
the Telerik team
I am reluctant to role out a new version on the basis that it _might_ fix our problem. We are not able to consistently reproduce this, so would not be able to determine if the new version has made a difference or not.
Are you able to point me to something in the 2010.3.1314 release note that would suggest this issue might be fixed, and give us more confidence in rollling out this update?
Thanks,
Matt
I installed the sp1 and it fixed the issue for me.
Thank you.
Are you able to repeatably reproduce this issue? In our scenario we are only getting this problem in test, and very very rarely ( about 5 times in 4 days).
Do you have a repro solution that you are able to share that might help us narrow down our use-case?
Thanks,
The SP1 fixed the issue I had with RadContextMenu.GetClickedElement (see my previous post).
Regards
With the Q3 SP1 2010 release we modified the ApplicationHelper class not to throw the exception that Shawn reported. And although I understand you uncertainty about upgrading your RadControls version, I am afraid that there isn't much that we can do to assist you unless we manage to reproduce your issue on our side.
So if you can isolate the issue and reproduce it in a specific scenario, we will be able to further investigate it and let you know if this fix will work for you as well.
All the best,
Tina Stancheva
the Telerik team