[UWP] Prevent Layouts with no background color from being input transparent (#4508)

* [UWP] Prevent Layouts with no background color from being input transparent; fixes #4360;

* Add comments

* Fix build for UITests projects
This commit is contained in:
E.Z. Hart 2018-11-28 12:03:57 -07:00 коммит произвёл GitHub
Родитель 2f6c6ec420
Коммит 39ceaebba2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 76 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.Issues.Issue4360">
<ContentPage.Content>
<StackLayout HorizontalOptions="FillAndExpand" HeightRequest="50">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_OnTapped"/>
</StackLayout.GestureRecognizers>
<Label x:Name="Label" BackgroundColor="Red" VerticalOptions="FillAndExpand" VerticalTextAlignment="Center"
Text="Tap next to this label (not on it); If the text changes to 'Success', the test has passed."
HorizontalOptions="Center" />
</StackLayout>
</ContentPage.Content>
</ContentPage>

Просмотреть файл

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;
namespace Xamarin.Forms.Controls.Issues
{
#if APP
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 4360, "UWP: TapGestureRecognizer works on Layout only if BackgroundColor is set",
PlatformAffected.UWP)]
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Issue4360 : ContentPage
{
const string Success = "Success";
public Issue4360()
{
InitializeComponent();
}
void TapGestureRecognizer_OnTapped(object sender, EventArgs e)
{
Label.Text = Success;
}
}
#endif
}

Просмотреть файл

@ -412,6 +412,10 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue4136.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue4262.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue4360.xaml.cs">
<DependentUpon>Issue4360.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)LegacyComponents\NonAppCompatSwitch.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MapsModalCrash.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ModalActivityIndicatorTest.cs" />
@ -1058,4 +1062,10 @@
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue4360.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>

Просмотреть файл

@ -617,6 +617,19 @@ namespace Xamarin.Forms.Platform.UWP
{
RemoveBackgroundLayer();
IsHitTestVisible = Element.IsEnabled && !Element.InputTransparent;
if (!IsHitTestVisible)
{
return;
}
// If this Panel's background brush is null, the UWP considers it transparent to hit testing (even
// when IsHitTestVisible is true). So we have to explicitly set a background brush to make it show up
// in hit testing.
if (Element is Layout && Background == null)
{
Background = new SolidColorBrush(Windows.UI.Colors.Transparent);
}
}
}