--- /dev/null
+<?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.Issue5057">
+ <StackLayout Padding="10">
+ <Label Text="When both Page.BackgroundImage and Page.BackgroundColor are set, the BackgroundImage takes precedence."/>
+ <Label Text="If Page.BackgroundImage is set, setting BackgroundColor won't be have any visual effect"/>
+ <Label Text="Clearing the BackgroundImage by setting it to null, makes Page background displayed with BackgroundColor"/>
+ <Button Text="Set background color to Red"
+ Clicked="BtnSetBkgndColorRed_Clicked"
+ BackgroundColor="White"/>
+ <Button Text="Set background image"
+ Clicked="BtnSetBkgndImg_Clicked"
+ BackgroundColor="White"/>
+ <Button Text="Set background color to default"
+ Clicked="BtnSetBkgndColorDefault_Clicked"
+ BackgroundColor="White"/>
+ <Button Text="Set background image to null"
+ Clicked="BtnSetBkgndImgNull_Clicked"
+ BackgroundColor="White"/>
+ </StackLayout>
+</ContentPage>
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+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, 5057, "Android: ContentPage BackgroundColor ignored in Forms ",
+ PlatformAffected.Android)]
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ public partial class Issue5057 : ContentPage
+ {
+ public Issue5057()
+ {
+ InitializeComponent();
+ }
+
+ void BtnSetBkgndColorRed_Clicked(object sender, System.EventArgs e)
+ {
+ BackgroundColor = Color.Red;
+ }
+
+ void BtnSetBkgndImg_Clicked(object sender, System.EventArgs e)
+ {
+ BackgroundImage = "test.jpg";
+ }
+
+ void BtnSetBkgndColorDefault_Clicked(object sender, System.EventArgs e)
+ {
+ BackgroundColor = (Color)BackgroundColorProperty.DefaultValue;
+ }
+
+ void BtnSetBkgndImgNull_Clicked(object sender, System.EventArgs e)
+ {
+ BackgroundImage = null;
+ }
+ }
+#endif
+}
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue4600.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Issue5057.xaml.cs">
+ <DependentUpon>Issue5057.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
<Compile Include="$(MSBuildThisFileDirectory)LegacyComponents\NonAppCompatSwitch.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MapsModalCrash.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ModalActivityIndicatorTest.cs" />
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue5057.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </EmbeddedResource>
+ </ItemGroup>
</Project>
\ No newline at end of file
Id = Platform.GenerateViewId();
}
- UpdateBackgroundColor(view);
- UpdateBackgroundImage(view);
+ UpdateBackground(false);
Clickable = true;
}
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == Page.BackgroundImageProperty.PropertyName)
- UpdateBackgroundImage(Element);
+ UpdateBackground(true);
else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
- UpdateBackgroundColor(Element);
+ UpdateBackground(false);
else if (e.PropertyName == VisualElement.HeightProperty.PropertyName)
UpdateHeight();
}
_previousHeight = newHeight;
}
- void UpdateBackgroundColor(Page view)
+ void UpdateBackground(bool setBkndColorEvenWhenItsDefault)
{
- if (view.Parent is BaseShellItem)
+ Page page = Element;
+
+ string bkgndImage = page.BackgroundImage;
+ if (!string.IsNullOrEmpty(bkgndImage))
+ this.SetBackground(Context.GetDrawable(bkgndImage));
+ else
{
- var background = view.BackgroundColor;
- var color = Context.Resources.GetColor(global::Android.Resource.Color.BackgroundLight, Context.Theme);
- SetBackgroundColor(background.IsDefault ? color : background.ToAndroid());
+ Color bkgndColor = page.BackgroundColor;
+ bool isDefaultBkgndColor = bkgndColor.IsDefault;
+ if (page.Parent is BaseShellItem && isDefaultBkgndColor)
+ {
+ var color = Context.Resources.GetColor(global::Android.Resource.Color.BackgroundLight, Context.Theme);
+ SetBackgroundColor(color);
+ }
+ else if (!isDefaultBkgndColor || setBkndColorEvenWhenItsDefault)
+ SetBackgroundColor(bkgndColor.ToAndroid());
}
- else if (view.BackgroundColor != Color.Default)
- SetBackgroundColor(view.BackgroundColor.ToAndroid());
- }
-
- void UpdateBackgroundImage(Page view)
- {
- if (!string.IsNullOrEmpty(view.BackgroundImage))
- this.SetBackground(Context.GetDrawable(view.BackgroundImage));
}
}
}
\ No newline at end of file