Xamarin.Forms
Xamarin.Forms copied to clipboard
[Bug] Setting button style at runtime on Xamarin.Forms > 5.0 does not work properly
Description
When setting the style of a button at runtime, it does not work properly for apps using Xamarin.Forms 5.0.x. When using Xamarin.Forms < 5.0, i.e. version 4.8.0.1821, then it works as expected.
Steps to Reproduce
- Open the attached repro project
- Compile and run it
- When it started, click on the button "Change style"
Expected Behavior
The button should change its properties to match all the properties set in the GreenButton style. The upper button should have a green background color.
Actual Behavior
In this repro project, it seems that only the text color is getting changed. The background color is getting ignored. The upper button keeps the red background color.
Basic Information
- Version with issue: 5.0.x
- Last known good version: 4.8.0.1821
- Platform Target Frameworks:
- iOS: latest
- Android: latest
Environment
Show/Hide Visual Studio info
=== Visual Studio Enterprise 2019 for Mac ===
Version 8.9.6 (build 6)
Installation UUID: 2766a82b-f007-49fd-9860-349420ce49f8
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)
Package version: 612000125
=== Mono Framework MDK ===
Runtime:
Mono 6.12.0.125 (2020-02/8c552e98bd6) (64-bit)
Package version: 612000125
=== Roslyn (Language Service) ===
3.9.0-6.21152.10+c10f884b30737542ddd84ca889a4aad9281ce210
=== NuGet ===
Version: 5.8.0.6860
=== .NET Core SDK ===
SDK: /usr/local/share/dotnet/sdk/5.0.202/Sdks
SDK Versions:
5.0.202
5.0.201
3.1.408
3.1.407
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks
=== .NET Core Runtime ===
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
5.0.5
5.0.4
3.1.14
3.1.13
=== .NET Core 3.1 SDK ===
SDK: 3.1.408
=== Xamarin.Profiler ===
Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Updater ===
Version: 11
=== Apple Developer Tools ===
Xcode 12.4 (17801)
Build 12D4e
=== Xamarin.Mac ===
Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.
=== Xamarin.iOS ===
Version: 14.14.2.5 (Visual Studio Enterprise)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:44-0500
=== Xamarin Designer ===
Version: 16.9.0.323
Hash: 1b4790c08
Branch: remotes/origin/d16-9
Build date: 2021-03-31 05:12:20 UTC
=== Xamarin.Android ===
Version: 11.2.2.1 (Visual Studio Enterprise)
Commit: xamarin-android/d16-9/877f572
Android SDK: /Users/timlandskron/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
None installed
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 30.0.2
Build Information:
Mono: 5e9cb6d
Java.Interop: xamarin/java.interop/d16-9@54f8c24
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.34.1@daff8f4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@d210f11
=== Microsoft OpenJDK for Mobile ===
Java SDK: /Users/timlandskron/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
=== Android SDK Manager ===
Version: 16.9.0.22
Hash: a391de2
Branch: remotes/origin/d16-9~2
Build date: 2021-03-24 08:30:26 UTC
=== Android Device Manager ===
Version: 16.9.0.17
Hash: fc2b3db
Branch: remotes/origin/dev/jmt/d16-9bump~1
Build date: 2021-03-24 08:30:44 UTC
=== Build Information ===
Release ID: 809060006
Git revision: 47cf16e38721a785b8e2296ce6716502f34261ac
Build date: 2021-04-07 07:23:18-04
Build branch: release-8.9
Xamarin extensions: 47cf16e38721a785b8e2296ce6716502f34261ac
=== Operating System ===
Mac OS X 10.16.0
Darwin 20.3.0 Darwin Kernel Version 20.3.0
Thu Jan 21 00:07:06 PST 2021
root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
Build Logs
Screenshots
Built with Xamarin.Forms 4.8.0.1821
Before button click (Style: RedButton)
After button click (Style: GreenButton)
Built with Xamarin.Forms 5.0.2012
Before button click (Style: RedButton)
After button click (Style: GreenButton)
Reproduction Link
Workaround
we face the same issue in our app. Any updates here?
I've done style changing using the info in here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/dynamic You change the style in the Resources instead of changing the property of the component
att.
We are facing the same issue. No problem in the earlier version, but in version X.F. 5+. We're using merged resource directories and are changing the button colors depending on the authenticated customer.