Hello,
The App crashes when I try to get the value in MAUI .NET 8. How to achieve this in .NET MAUI?
You can do it by Application.Current.Resources.TryGetValue
like following code.
var res =Application.Current.Resources.TryGetValue("BorderThickness", out object r2) ;
if (res)
{
Microsoft.Maui.Controls.OnPlatform<Microsoft.Maui.Thickness> resThickness = (Microsoft.Maui.Controls.OnPlatform<Microsoft.Maui.Thickness>)r2;
var AndroidPlatformsThinkness = resThickness.Platforms[1].Value;
}
Here is a document about:Access resources by key from code
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.