Force Position of ContextMenu

10 posts, 0 answers
  1. Erik
    Erik avatar
    22 posts
    Member since:
    May 2011

    Posted 05 Jun 2012 Link to this post

    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!
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 08 Jun 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. Hu
    Hu avatar
    1 posts
    Member since:
    Sep 2012

    Posted 01 Sep 2012 Link to this post

    This context menu is dynamic and requires you to fire the call from a particular list item.Replica Handbags And Shoes

  5. Erik
    Erik avatar
    22 posts
    Member since:
    May 2011

    Posted 18 Dec 2012 Link to this post

    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!
  6. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 31 Dec 2012 Link to this post

    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.
  7. Erik
    Erik avatar
    22 posts
    Member since:
    May 2011

    Posted 17 May 2013 Link to this post

    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?
  8. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 23 May 2013 Link to this post

    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.
  9. Erik
    Erik avatar
    22 posts
    Member since:
    May 2011

    Posted 23 May 2013 Link to this post

    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)

  10. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 27 May 2013 Link to this post

    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.
  11. Erik
    Erik avatar
    22 posts
    Member since:
    May 2011

    Posted 29 May 2013 Link to this post

    This helped, thanks. It works now without the error!
Back to Top
DevCraft banner