This is a migrated thread and some comments may be shown as answers.

Force Position of ContextMenu

9 Answers 130 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 2
Erik asked on 05 Jun 2012, 05:20 PM
I have a context menu attached to a list, and one of the issues I encounter is the position is always related to the list item. Adding +/- to the margin does not help because it is still originating from the list item. This context menu is dynamic and requires you to fire the call from a particular list item.

I was wondering if there is a way to define a unified location for the context menu position, like always appear at "0,0" rather than the parent object position which called it.

Any ideas appreciated!

9 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 08 Jun 2012, 12:12 PM
Hi Erik,

Thank you for writing.
You can position RadContextMenu anywhere with the help of the Offset and RegionOfInterest properties. If RegionOfInterest is null, the position of the menu owner is used as a region of interest instead.
Please write again if you have other questions.

All the best,
Victor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Hu
Top achievements
Rank 1
answered on 01 Sep 2012, 08:47 AM
This context menu is dynamic and requires you to fire the call from a particular list item.Replica Handbags And Shoes

0
Erik
Top achievements
Rank 2
answered on 19 Dec 2012, 04:35 AM
Can you give an example of how this would be done? Given that I have access to the list item that is clicked, how do I know how to offset the menu? If I want the context menu to stay in the center of the screen, I can't define two rectangles with region of interest. The only option is to offset the menu at run time which seems a little complicated. Would I have to know how many pixels the screen has? and then do math on the position of the clicked item to set a new offset?

My end goal is pretty simple. No matter where or what I click, I want my context menu to be right in the middle. Thanks in advance!
0
Victor
Telerik team
answered on 31 Dec 2012, 10:53 AM
Hi Erik,

Thanks for writing.
If your context menu has the same height for every item (for example if the context menu has the same menu items always) you can simply set the RegionOfInterest to some rectangle on top of the page so that when the menu opens, it positions itself below it (which should be the center of the screen). Different screen sizes should not matter because you can calculate your region of interest once when the app is launched based on the screen size (also on orientation change if your app supports it).

If your context menus can be different however, you will have to tweak the region of interest every time a menu opens in order to take into account the height of the menu that will open.

It is obvious that these suggestions are less than ideal for this particular scenario. We will consider implementing absolute positioning of the context menu in the next release. For example contextMenu.AbsolutePosition = Center, or contextMenu.AbsolutePosition = Top. 

Please write again if you have other questions and thanks for the feedback.

Regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Erik
Top achievements
Rank 2
answered on 17 May 2013, 05:11 PM
Thanks for the info, but I'm still not sure how you would do this. What does the XAML look like to assign a rectangle? if I were to do it in the code, how would you assign it? When I'm assigning it a rectangle, what is it actually setting the origin to? 0,0 of my context menu is aligning to what point on the rectangle?

Is there a roundabout way to just always set the position of the context menu in the code behind?
0
Victor
Telerik team
answered on 23 May 2013, 11:53 AM
Hello Erik,

Please have a look at this help article. More concretely the RegionOfInterest section. When RegionOfInterest is not set, it uses the layout slot of the element with which the menu is associated. By setting RegionOfInterest you are explicitly telling the menu to use a custom rectangle.

Regards,
Victor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Erik
Top achievements
Rank 2
answered on 23 May 2013, 06:38 PM
Because my context menu is in a  template on a radjumppanel, I can't add new XAML or do anything programmatically. 

I tried to add a rect to my Region of Interest but I get a XAML / Wrapped / Runtime error.
.....
       <telerikPrimitives:RadContextMenu.RegionOfInterest>
                            <Rect X="0" Y="200" Width="480" Height="800"></Rect>
       </telerikPrimitives:RadContextMenu.RegionOfInterest>
.....

   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at Telerik.Windows.Controls.StackVirtualizationStrategy.MeasureContainer(RadVirtualizingDataControlItem container)
   at Telerik.Windows.Controls.VirtualizationStrategy.GetContainerForItem(IDataSourceItem item, Int32 insertAt)
   at Telerik.Windows.Controls.StackVirtualizationStrategy.GetContainerForItem(IDataSourceItem item, Int32 insertAt)
   at Telerik.Windows.Controls.VirtualizationStrategy.GetContainerForItem(IDataSourceItem item, Boolean insertLast)
   at Telerik.Windows.Controls.VirtualizationStrategy.ManageLowerViewport(Boolean recycle)
   at Telerik.Windows.Controls.RadVirtualizingDataControl.ManageViewport()
   at Telerik.Windows.Controls.RadVirtualizingDataControl.BalanceVisualSpace()
   at Telerik.Windows.Controls.RadVirtualizingDataControl.CleanupAfterCollectionReset()
   at Telerik.Windows.Controls.RadVirtualizingDataControl.OnCollectionReset()
   at Telerik.Windows.Controls.RadVirtualizingDataControl.UpdateViewportOnItemsChange(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.RadVirtualizingDataControl.OnItemsChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.RadDataBoundListBox.OnItemsChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.RadJumpList.OnItemsChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.Primitives.DataControlBase.OnListSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadListSource.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadListSource.RefreshOverride()
   at Telerik.Windows.Data.RadCollectionViewSource.RefreshOverride()
   at Telerik.Windows.Data.RadListSource.Refresh()
   at Telerik.Windows.Data.RadListSource.SourceCollectionChangedOverride(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadCollectionViewSource.SourceCollectionChangedOverride(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadListSource.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadListSource.Telerik.Windows.Data.IWeakEventListener.ReceiveEvent(Object sender, EventArgs e)
   at Telerik.Windows.Data.WeakEventHandler`1.ProcessEvent(Object sender, EventArgs e)
   at Telerik.Windows.Data.WeakEventHandler`1.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at ShowSeek.RangeObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at ShowSeek.RangeObservableCollection`1.AddRange(IEnumerable`1 items)
   at ShowSeek.MainPage.BuildMainList()
   at ShowSeek.MainPage.<DataBinderWork>b__6()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Delegate.DynamicInvokeOne(Object[] args)
   at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
   at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
   at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
   at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
   at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

0
Victor
Telerik team
answered on 27 May 2013, 10:35 AM
Hi Erik,

Thanks for writing.
It appears that the XAML infrastructure does not like struct types, which Rect happens to be. You can try creating a sort of global view model with a property of type Rect that you can bind to. For example if your global view model is inserted in your app resources and its key is "ViewModel", you can try setting the region of interest like this:

<telerikPrimitives:RadContextMenu RegionOfInterest="{Binding RegionOfInterest, Source={StaticResource ViewModel}}"/>

Regards,
Victor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Erik
Top achievements
Rank 2
answered on 30 May 2013, 01:02 AM
This helped, thanks. It works now without the error!
Tags
ContextMenu
Asked by
Erik
Top achievements
Rank 2
Answers by
Victor
Telerik team
Hu
Top achievements
Rank 1
Erik
Top achievements
Rank 2
Share this question
or