How to access or share resource dictionary between MAUI application and library

Anil Joseph 0 Reputation points
2024-03-06T06:16:00.61+00:00

I have a ContentPage in a MAUI library which is referring to a color defined in the resources of the App.xaml which is in the main MAUI project.

ContentPage in Library uses: BackgroundColor="{StaticResource White2}"

App.xaml in the MAUI application project defines: <Color x:Key="White2">#FFFFFF</Color>

On running the application there is a runtime error: Cannot fing resource White2.

How do i access(share) the resource dictionary declared in the App.xaml to a MAUI library project?

I tried the AI assisted solution, but Application.Current is null in the constructor of the ContentPage

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,135 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,561 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
781 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more