Hi Team,
In order to provide the key navigation support to our custom control in Xamarin.Forms.macOS platform, we have used the addlocalmonitorforeventsmatchingmask in the Custom Renderer to detect the Keyboard pressed action and it raises as expected when key is pressed and achieved our requirement.
Issue we are facing:
If we use the two custom view with different instance and loaded in a view and key down or any key is pressed, the event handler gets triggered for both the view and key navigation is performed for both.
Note:
1. We have tried to handle the event by using keyEvent.Handle = IntPtr.Zero, and it handles the event as expected for second custom view. But if we click the second custom view and perform the key navigation, the event triggers for the first custom view only and unable to perform the key navigation for custom view in any manner.
Also, tried to perform the key navigation only when the custom view is focused. So, while tapping the first custom view, we have set the Focus to first custom view and performed the key navigation. But if we tap the second custom view, the first custom view’s focus is not reset and the second custom view too gets focused and the results are same as mentioned above.
Additionally, we have also tried by override the KeyDown event, but it does not raised.
Code Example:
PCL View:
``public class CustomView : Grid
{
internal void PerformKeyNavigationProcess()
{
//do the key pressed operation here
}
}``
macOS platform :
``public class CustomControlRenderer : VisualElemenRenderer<CustomView>
{
private NSObject localKeyEventmonitor;
public Custom ControlRendererolRenderer()
{
localKeyEventmonitor = NSEvent.AddLocalMonitorForEventsMatchingMask(NSEventMask.KeyDown,KeyEventHandler);
}
private NSEvent KeyEventHandler(NSEvent keyEvent)
{
return keyEvent;
}
}``
Can anyone help us to overcome from this issue and achieve our requirement?
Regards,
Dinesh Babu Yadav