-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some properties not updating (eg VisualState setter not working for Button BackgroundColor) with AOT enabled #11662
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
I tried a few things, but found something that makes me feel this is an Android AOT issue... somehow. If I force XamlC in debug, no issue: <_MauiForceXamlCForDebug>True</_MauiForceXamlCForDebug> If I disable the AOT but keep trimming on, no issue: <PublishTrimmed>true</PublishTrimmed>
<RunAOTCompilation>false</RunAOTCompilation> However, If I now enable AOT, the issue returns: <PublishTrimmed>true</PublishTrimmed>
<RunAOTCompilation>true</RunAOTCompilation> @jonathanpeppers @rolfbjarne how would one go about seeing where/why this happens? |
There is a workaround in #8961 that seems to work as well:
|
Comments in #8961 also seem to indicate this happens for iOS on TestFlight - probably mono AOT at this point... |
Related to #9753 ? |
/cc @fanyang-mono |
So @steveisok and @fanyang-mono - are there any working theories on why this is happening? Is there anything we can be doing on our side to move this forward? |
@hartez Nothing off the top of my head. I expect it's going to take a bit of sleuthing. @fanyang-mono when do you expect to be able to work on this? |
I could start working on this next week. First, I will be working on creating an app hopefully a desktop app, which could reproduce this issue. That would be easier for me to debug Mono with. |
I have migrated the Xamarin forms app to .NET MAUI. Is there any Handler/Renderer way so that I can write one place and fixes everywhere. @mattleibow @jonathanpeppers @fanyang-mono |
I am afk now, so apologies for the short reply... You can try adding a new mapper in mauiprogram.cs ViewHandler.ViewMapper.AppendToMapping(nameof(VisualElement.BackgroundColor), (v, h) => h.UpdateValue(nameof(IView.Backgeound))); |
Hi @mattleibow, |
Interested as well in eventual workarounds for .NET 7. |
I am here just to tell you that the BackgroundColor doesn't change even when in debug, tested on a fresh project and building it for windows. How come that nobody tested the "isEnabled" flag on a button? |
As denhaandrei mentioned, the only change I needed to do in my MAUI application to avoid this problem is in the file --- a/mauiproject/Resources/Styles/Styles.xaml
+++ b/mauiproject/Resources/Styles/Styles.xaml
@@ -25,7 +25,7 @@
<Style TargetType="Button">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Primary}}" />
- <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}" />
+ <Setter Property="Background" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}" />
<Setter Property="FontFamily" Value="OpenSansRegular"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="CornerRadius" Value="8"/>
@@ -39,7 +39,7 @@
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}" />
- <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}" />
+ <Setter Property="Background" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup> |
Yes we know of this solution but this would override all the BackgroundColor property set anywhere in the app. Which can be issue when migrating Xamarin apps where people were not using Background property at all. In that case you would have to replace BackgroundColor with Background through out the app which is not cool at all. |
I had to solve it for my customer too, so I disabled AOT compilation in project by adding this line into my CSPROJ file in the first "PropertyGroup". This was the fastest way to solve it, since the issue is opened for more then half year... |
Thanks for the clarification. But does anything speak against using this workaround for apps that are freshly created with Maui? |
The only thing you need to make sure if you are using this workaround is that from now wards you need to use Backgroud property to change/set backgroundcolor property of Button. Setting BackgroundColor will have no effect and will be override by the Background value set in ButtonStyle in App.xaml if not explicitly set on particular Button. Yup For new apps this works good enough |
I found a workaround for now that is quite simple: Remapping the property from BackgroundColor to Background fixed the issue. This is easy to do in the maui program app builder: .ConfigureMauiHandlers(_ =>
{
LabelHandler.Mapper.AppendToMapping(
nameof(View.BackgroundColor),
(handler, View) => handler.UpdateValue(nameof(IView.Background)));
ButtonHandler.Mapper.AppendToMapping(
nameof(View.BackgroundColor),
(handler, View) => handler.UpdateValue(nameof(IView.Background)));
}) |
Will this be fixed soon, it is very fundamental for us to be able to release that the buttons show no colour on pressing. Testing in debug is of course all ok. I am beginning to despair that it is impossible to release a large Maui project to customers. |
When will this bug be fixed? |
This bug is fixed but will not be backported to .NET 7 as the changes required are too extensive. There is a workaround and .NET 8 RC 1 (with a go live license too I think) has the fix. |
Description
The setter is not working properly when in release mode. In debug it works fine.
Only noticed it for the backgroundcolor on button. TextColor works fine for button. Didn't test anything other.
Also only tested on android, don't now if it's the same for other platforms.
I created a simple project to demonstrate. It's basicly the templete that you get when createing a new project with added checkbox to enable/disable the button:
Only the text color changed but the background didn't in release mode.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/Kaiffa/maui-bug-visualstate-button-release
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12.0
Did you find any workaround?
Remapping the property from BackgroundColor to Background fixed the issue. This is easy to do in the maui program app builder:
Relevant log output
The text was updated successfully, but these errors were encountered: