ContextMenu on a Mac

7 posts, 0 answers
  1. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 18 Jun 2009 Link to this post

    Hi,

    Is there a recommended method of getting context menus working on Macs? I don't have a Mac to test on at the moment, but understand that they don't support 'windowless' or right-click. Is this correct? If so, what's the best way of getting a context menu working? I'd like to use the same code for windows and macs, so need something that seems natural on the windows platform too.

    Thanks, James.
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 19 Jun 2009 Link to this post

    Hi James,

    You are right, that on Mac the right-click support is missing. Unfortunately the best cross-platform option at the moment would be opening the context menu on left-click + modifier key, for example Ctrl. However, this does not seem very intuitive for the Windows users. Since this is a platform limitation, we can't do much, except keep searching for Mac specific hack that will enable us to catch the right click.

    Kind regards,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 19 Jun 2009 Link to this post

    Hi Valeri,

    Thanks for your answer. You're right - ctrl+left-click isn't going to please my Windows users! Is it possible to tie both events up to the menu? i.e. to have the ContextMenu appear to ctrl+left click and right-click? Mac users would ctrl+left-click for now and Windows users would have the choice of either.

    Thanks for your help, James.
  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 19 Jun 2009 Link to this post

    Hello James,

    I will need some time to prepare a sample, opening the context menu at the right position appears to be harder than I thought. I hope that I will be able to send you an example by Tuesday next week. Thank you for your patience.

    Best wishes,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Jonathan Miller
    Jonathan Miller avatar
    57 posts
    Member since:
    Jun 2008

    Posted 25 Jun 2009 Link to this post

    Hi Valeri, please post the Mac sample to this forum when you have it available.  I have the same issue with Mac users.  Thanks
  7. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 03 Jul 2009 Link to this post

    Hi guys,

    Please, find attached the promised sample.

    There are two things to mention - browser detection and context menu configuration:
    - Since the Windowless mode is required for the right-click functionality to operate properly, but it is not supported in Safari, I added the following code in the ASPX page:
    <object data="data:application/x-silverlight-2," id="Xaml1" type="application/x-silverlight-2" width="100%" height="100%">
     <param name="source" value="ClientBin/ContextMenuDifferentEventNameOnMacAndPC.xap" />
     <param name="background" value="#FFFFFF" />
     <% if (!Request.Browser.IsBrowser("Safari")) { %>
     <param name="Windowless" value="true" />
     <% } %>

     <param name="minRuntimeVersion" value="2.0.30818.0" />
    </object>


    If you are not very much into ASP.NET, this is a server-side check that detects Safari and renders, or does not render the Windowless parameter, depending on the browser. This trick will not work in HTML page, so if you need to host your Silverlight plug-in in a HTML page, you will have to search for another workaround.

    From now on the context menu configuration is easy:
    bool rightClickAllowed = Application.Current.Host.Settings.Windowless;
    if (rightClickAllowed)
    {
     // By default RadContextMenu will open on Right click.
     this.InstructionsText.Text = "Right click the red rectangle to open a context menu";
    }
    else
    {
     // Set EventName and ModifierKey for Mac users
     this.ContextMenu1.ModifierKey = ModifierKeys.Control;
     this.ContextMenu1.EventName = "MouseLeftButtonDown";
     this.InstructionsText.Text = "Ctrl+LeftClick the red rectangle to open a context menu";
    }

    I hope this helps.

    Greetings,

    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 10 Jul 2009 Link to this post

    Hi Valeri,

    Thanks for your answer and example. I've added your code to my aspx page and the app runs fine. I'll be getting a mac next week for testing...

    Thanks for your help, James.
Back to Top
DevCraft banner