dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Bound VisualState property does not get read at item creation #15464

Open sjorsmiltenburg opened 1 year ago

sjorsmiltenburg commented 1 year ago

Description

I have defined 2 VisualStates A and B. In an Extension property I set the default value to A. On an visualelement I bind to the property

Problem: When the control is added to the screen, the visual state is not A but "Normal". It seems the state property is only read when I trigger a state change after creation.

After switching states it goes from Normal -> A -> B -> A -> B Expected: A->B->A->B->A

see linked repo for an example.

Additional problems: 1) When switching style these warnings are outputed in the console Microsoft.Maui.Controls.Element: Warning: Microsoft.Maui.Controls.LinearGradientBrush is already a child of Microsoft.Maui.Controls.Grid. Remove Microsoft.Maui.Controls.LinearGradientBrush from Microsoft.Maui.Controls.Grid before adding to Microsoft.Maui.Controls.Grid. Microsoft.Maui.Controls.Element: Warning: Microsoft.Maui.Controls.SolidColorBrush is already a child of Microsoft.Maui.Controls.Grid. Remove Microsoft.Maui.Controls.SolidColorBrush from Microsoft.Maui.Controls.Grid before adding to Microsoft.Maui.Controls.Grid.

2) visual studio complains about my extension property, but builds succesfully Error XLS0415 The attachable property 'MyVisualState' was not found in type 'MyVisualStateExtension'. zz_maui_windows_visualstategroupbug C:_Sources\zz_maui_visualstatebug\MainPage.xaml 91

Steps to Reproduce

download repo build (i tested on windows)

Link to public reproduction project repository

https://github.com/sjorsmiltenburg/maui_visualstatebug.git

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

windows

Did you find any workaround?

my workaround for now is to rename A to Normal

Relevant log output

No response

Zhanglirong-Winnie commented 9 months ago

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 3. Can repro on windows platforms with sample project. https://github.com/sjorsmiltenburg/maui_visualstatebug.git image