Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Android] Fix issue updating background brush #13025

Closed
wants to merge 9 commits into from
Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestContentPage
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Controls.Issues.Issue13017">
<StackLayout>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="Switch between both Backgrounds several times. If the change works as expected, the test has passed."/>
<StackLayout>
<Frame
WidthRequest="50"
HeightRequest="100"
Padding="0">
<Frame.Style>
<Style TargetType="Frame">
<Style.Triggers>
<DataTrigger TargetType="Frame"
Binding="{Binding BackgroundNumber}"
Value="1">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush
StartPoint="0,0"
EndPoint="1,0.5">
<GradientStop Color="#00FFD1" Offset="0"/>
<GradientStop Color="#5263FF" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger TargetType="Frame"
Binding="{Binding BackgroundNumber}"
Value="2">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="Red"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Frame.Style>
</Frame>
<Button
Text="Use Gradient"
Command="{Binding SelectGradient}"/>
<Button
Text="Use SolidColorBrush"
Command="{Binding SelectSolidBrushGradient}"/>
</StackLayout>
</StackLayout>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;

#if UITEST
using Xamarin.UITest;
using Xamarin.UITest.Queries;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(UITestCategories.Brush)]
#endif
#if APP
[XamlCompilation(XamlCompilationOptions.Compile)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 13017, "[Bug] Background doesn't change from LinearGradientBrush to SolidColorBrush by DataTrigger on Android",
PlatformAffected.Android)]
public partial class Issue13017 : TestContentPage
{
public Issue13017()
{
#if APP
Title = "Issue 13017";
InitializeComponent();
BindingContext = new Issue13017ViewModel();
#endif
}

protected override void Init()
{

}
}

[Preserve(AllMembers = true)]
public class Issue13017ViewModel : INotifyPropertyChanged
{
int _backgroundNumber = 1;

public Issue13017ViewModel()
{
SelectGradient = new Command(() =>
{
BackgroundNumber = 1;
});

SelectSolidBrushGradient = new Command(() =>
{
BackgroundNumber = 2;
});
}

public event PropertyChangedEventHandler PropertyChanged;

public ICommand SelectGradient { get; private set; }
public ICommand SelectSolidBrushGradient { get; private set; }

public int BackgroundNumber
{
get => _backgroundNumber;
set
{
_backgroundNumber = value;
OnPropertyChanged(nameof(BackgroundNumber));
}
}

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue8988.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12084.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12512.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13017.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8981.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3311.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12473.xaml.cs">
Expand Down Expand Up @@ -2221,6 +2222,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12084.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13017.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8981.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ void UpdateBackground()
this.SetBackground(null);

_backgroundDrawable = new GradientDrawable();

_backgroundDrawable.SetShape(ShapeType.Rectangle);
this.SetBackground(_backgroundDrawable);

UpdateBorderColor();
UpdateCornerRadius();
}
Expand Down