Custom ContentPage renderer and/or custom NavigationPage renderer on UWP RRS feed

  • Question

  • User89714 posted

    I have custom renderers for multiple Xamarin.Forms.Views. On UWP, these renderers (amongst other things) implement access key support (so that users can do things such as hit Alt+P to move the focus to whichever View 'P' is associated with). To do that, the renderers handle AccessKeyDisplayRequested and AccessKeyDisplayDismissed.

    I also want to handle AccessKeyDisplayRequested and AccessKeyDisplayDismissed at the page level, for ContentPage (and possibly NavigationPage). However, there is a distinct lack of examples of page renderers on UWP. The only one I have implemented previously has completely replaced the underlying page. However, in this instance, all I want to do is to add two event handlers to an existing page (rather than replace it), and to remove those handlers when the page is popped to avoid memory leaks.

    Can anybody point me at a sample that does anything similar please (not necessarily access key related, just adding/removing events to UWP pages in a custom renderer)?

    Monday, March 11, 2019 12:25 PM

All replies

  • User371688 posted

    Maybe you can check: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/windows/visualelement-access-keys

    Tuesday, March 12, 2019 9:16 AM
  • User89714 posted

    Thanks @jezh . I hadn't realised that the platform-specifics already included AccessKey support. Thankfully, I haven't wasted time implementing it myself, as I need functionality that goes beyond what the platform-specifics implementation does, hence my question about page renderer samples. I basically need a bool bindable property that I can bind to that tells me whether the Access Keys are currently being displayed. I was hoping to handle AccessKeyDisplayRequested and AccessKeyDisplayDismissed in a ContentPage renderer or a NavigationPage renderer, but investigation last night suggests that those events are only called if the related UI element has its own AccessKey. As I don't want to show an AccessKey for the page, it seems that I won't be able to do the event handling at page level (unless I have missed something). Unfortunately, that suggests that I have to update the bool property from every one of the UWP custom renderers that I have for interactive Views, which means it will be slightly less efficient, but not the end of the world.

    Although it looks like it won't help with this, I'd still be interested in seeing examples of custom UWP ContentPage and NavigationPage renderers that customise existing pages (including adding & removing event handlers) rather than creating completely new pages.

    Tuesday, March 12, 2019 10:27 AM
  • User89714 posted

    BTW @jezh, am I correct in thinking that the Xamarin.Forms WebView on UWP eats the Alt key, so that if the user has tabbed to put the focus on the WebView and then presses the Alt key, no access keys are displayed? That's what appears to be happening on XF 3.4

    Tuesday, March 12, 2019 5:20 PM
  • User175716 posted

    I implemented 'hotkeys' for UWP Forms application using Effects. So it can be attached at any level: page, control, whatever you want. From the other hand there is guarantee that it will be detached - and you will be able to unsubscribe from all necessary events.

    Wednesday, March 13, 2019 1:17 PM
  • User89714 posted

    @"anton.emelyancev" said: I implemented 'hotkeys' for UWP Forms application using Effects.

    Yes, that's a perfectly way to do the basic bits of handling access/shortcut/hot keys on UWP.

    Have you found a way at page level of being notified when access keys are being displayed/requested, without the page itself having a visible access key?

    Have you found a way of having WebView not swallow the Alt key, so that other Views on a page show their access keys when the user hits Alt when the focus is on a WebView?

    Wednesday, March 13, 2019 3:43 PM
  • User175716 posted

    I haven't faced such issues since I used only basic functionality: press X-key, fire event/command. No WebViews - no issues ;) I subscribed to Window.Current.CoreWindow.KeyDown event so doesn't need to have actual access keys (if I understood correctly what is it). Though KeyDown is sort of global event I had 'local' subscriptions for certain keys when it made sense - 'space bar' key for video player, etc. I only had to deal with multiple subs for the same key - I fired event/command only for the last attached Effect. That approach worked for me well.

    Thursday, March 14, 2019 6:57 AM