简体   繁体   中英

Overlay layer without interactivity in Xamarin.Forms

Recently Xamarin.Forms changed its behavior for controls with Clear and Default background. The changes are described in this PR: https://github.com/xamarin/Xamarin.Forms/pull/935

This change was quite a breaking change in two of my apps. The default XAML behavior in UWP and WPF is that when Background is clear ( x:Null ), the visual is click-through, but If it has some children, you can still interact with them. This is very important especially for mapping apps where you often need map control and then layout some control above it. If I set the layer to InputTransparent user cannot interact with any controls in the layer in any way, if I don't set it, then I cannot interact with the map itself.

The problem is that I don't see any easy workaround to this, because I cannot layout the controls without a layout parent. If I want to lay them out in a grid, I need a Grid above them. and that will block the map. Same with any other layout.

I want to achieve something like the following:

<CustomMapControl />
<Grid x:Name="ControlsGrid">
   <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="*" />
   </Grid.RowDefinitions>
   <Button Grid.Row="1" Text="Zoom in" />
</Grid>
<AboluteLayout x:Name="PlaceMenuContainer" />

This code now will not allow me to interact with the map, because the Grid occludes it. If I add InputTransparent="True" to the Grid, I cannot interact with the button anymore, as the touch interactions are no longer dispatched to them (see VisualInputRenderer, line 52 - 64 ). Also note that I can have multiple layers above the map, like the PlaceMenuContainer which is a container for context menu items which are displayed above the map when the user taps a certain location on the map. This means I cannot easily use a single layout container for all controls...

Do you see any way around this?

I got a confirmation from EZ Hart from the Microsoft Xamarin Team that this issue is currently looked at, and that several developers have run into this problem. Either a workaround of a new approach will be implemented soon, any updates will be posted on the related bug in Bugzilla :-).

Did you try something like

<Grid>
   <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition />
   </Grid.RowDefinitions>
   <CustomMapControl Grid.RowSpan="2"/>
   <Button Grid.Row="1" Text="Click me" />
</Grid>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM