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.26k stars 1.76k forks source link

Dynamic resource value is not applied for the property #25978

Open Abinaya-SF4661 opened 3 days ago

Abinaya-SF4661 commented 3 days ago

Description

I created a CustomContentView class which inherits ContentView and created a LabelStyle class which inherits Element. In CustomContentView class, I set its content as Label and created a bindable property for LabelStyle. In LabelStyle class, I created a bindable property called BackgroundColor and created a SetBackgroundColor method which is used to apply the color by checking the IsSet method.

I set the Color in ResourceDictionary with key. Using the key, I set the BackgroundColor property as Dynamic resource inside LabelStyle property. By setting this way, the color from ResourceDictionary is not applied to the property. Initially, when the control is called the value of dynamic resource is applied to the property. So, while checking the IsSet method, it should return true. If IsSet is true, then the default color is not applied to the property. But in this case, IsSet is return false, so the default color is re applied to the BackgroundColor property.

But, when setting the LabelStyle in the Resource dictionary and apply this style to LabelStyle property as Dynamic resource in CustomContentView, the value is applied to the LabelStyle.

Steps to Reproduce

Run the attached application

Expected Outcome - given color in Dynamic resource is applied to the property Actual Outcome - the default color of property applied

Sample.zip

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, Android, macOS, iOS

Affected platform versions

No response

Did you find any workaround?

when setting the LabelStyle in the Resource dictionary and apply this style to LabelStyle property as Dynamic resource in CustomContentView, the value is applied to the LabelStyle.

Refer the below image to reproduce this case in the above sample Image

Relevant log output

Nil

ninachen03 commented 2 days ago

This issue has been verified using Visual Studio 17.13.0 Preview 1.0 (9.0.10& 9.0.0 &9.0.0-preview.7.24407.4 &8.0.100 &8.0.3). Can repro it. Image