radimitrov / CSharpShellApp

77 stars 18 forks source link

DynamicResource not working after .net 8 update #354

Closed devastaza closed 6 months ago

devastaza commented 6 months ago

But it works in Styles.xaml file only. If i set BackgroundColor = from DynamicResource then after changing value of key object doesn't change it's color.

radimitrov commented 6 months ago

Are you sure the exact same thing worked in .NET 7? There shouldn't be any reason DynamicResource wouldn't work in .NET 8, though not everything "accepts" them if I remember correctly. Without seeing actual code I can't confirm anything right now. Could be a bug in the IDE, intended behavior change in .NET 8 or even a typo in your code.

devastaza commented 6 months ago

Sure, i'll try to explain my problem.

This part of code from .xaml file.

<Label
 Text = "D"
 TextColor = "{DynamicResource Primary}"
 FontSize = "22"/>

It setup the "D" you can see on screenshot belove. Screenshot_2023-12-14-15-10-17-497_com.radinc.csharpshell.png

So i can change value of my "Primary" key by pressing buttons on this page. ...And i change it.

And look, other objects change its background colors (cuz they have no setter {DynamicResource Primary}) Screenshot_2023-12-14-15-15-31-650_com.radinc.csharpshell.png

For example there is a wide button's code

<Button
 Text = "Dynamic Colors [Experimental]"
 Margin = "15"
 HeightRequest = "90"
 Clicked = "EnableDynamicColors"/>

And there is code from Styles.xml which setup all of my objects in this project.

<Style TargetType="Button">
    <Setter Property="BackgroundColor" Value="{DynamicResource Primary}" />

And this code worked on previous version of .net.

radimitrov commented 6 months ago

@devastaza Here is a .NET 8 test project. It qualifies as DynamicResources. And it works exactly the same under Windows and C# Shell. Maybe this is an light/dark theme thing? C# Shell should support these themes now, but I don't think it did before.

MauiAppDynamicResourceTest.zip

https://github.com/radimitrov/CSharpShellApp/assets/56889141/ddf66af8-86dc-434a-8840-b4d5fa9d153b

devastaza commented 6 months ago

@radimitrov i modified your example with DynamicResource properties and it works perfectly. Idk where is problem in my project. Btw thank u!