Open ivan-todorov-progress opened 2 years ago
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 had already reported this issue https://github.com/dotnet/maui/issues/9050. I ended up not using implicit styles
@arivoir: The issue https://github.com/dotnet/maui/issues/9050 is already closed. This explains why I have not found anything while searching for similar bugs. I completely disagree with Microsoft that implicit styles should call the property setters of the inherited class before the constructor. This is a well-known anti-pattern and there are numerous ways to avoid that. In their current state, implicit styles should be avoided. For this reason, I would prefer to leave this bug as open. If you agree with me, please, add your vote.
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 2.0. Can repro on windows platform with sample project. https://github.com/ivan-todorov-progress/maui-app-implicit-style-bug
This causes a bunch of NREs over here : /
Completely ridiculous that this is still open and unaddressed. I have been converting a large xam forms project and at every turn I find MAUI stuff that isn't even at base parity with the xam forms it replaced. Chasing down all these little quirks is stupid and a waste of time. If Maui wasn't ready it shouldn't have been released. Ready would be 100% analogous features and performance. I purposely waited as long as I could to convert but now mobile SDKs have forced me to. I thought by now all this would work. So unbelievably disappointed. I wish microsoft never bought Xamarin.
Description
This undesired behavior is a major source of problems, which is preventing the usage of implicit styles in many cases.
For example, let's declare following custom component:
The sole purpose of the above code is to trace the time when the properties are set in respect to the class's constructor.
If we apply an implicit style to this component in the page's resources, everything works as expected, e.g.:
The above XAML code snippet generates the following debug output:
First the class's constructor is called, then the
FirstColor
property is set by the implicit style. This is the normal behavior, every developer would normally expect.However, if we apply an implicit style to the component in
App.xaml
, everything runs backwards, .e.g.:The previous XAML code snippet generates the following debug output:
The property
SecondColor
is set first, and then the class's constructor is called. If theCustomComponent
class has some non-trivial initialization logic there, that would break things, because the class is not initialized yet, but we try to alter its state.The expected behavior is to apply all implicit styles after the class's constructor is called, otherwise it is too difficult or even impossible to cope with a partially initialized class.
Steps to Reproduce
Run the sample project from the provided link and observe the debug output:
SecondColor
property of theCustomComponent
class is set before theCustomComponent
constructor is called.CustomComponent
constructor is called.FirstColor
property of theCustomComponent
class is set after theCustomComponent
constructor is called.Link to public reproduction project repository
https://github.com/telerik/ms-samples/tree/main/Maui/AppImplicitStyle
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
N/A
Did you find any workaround?
The only workaround I have found so far is to avoid implicit styles declared in
App.xaml
entirely. Explicit named styles should be used everywhere instead.Relevant log output
No response