In ./Styles/Colors.xaml
I have a bunch of colors like this:
<Color x:Key="IIT_Purple">#6A00FF</Color>
Which I can reference in my platform-non-specific code using {StaticResource IIT_Purple}
However when I try to use them in ./Platforms/Windows/App.xaml
the program hits a break with an unhandled exception:
(Click to enlarge)
If I duplicate the <Color>
‘s from Colors.xaml
in to App.xaml
then they work perfectly – but this goes against the DRY/WET principle since it is duplicating the code.
Similarly in ./Platforms/Windows/App.xaml.cs
I have had to duplicate the colors again, like so:
var IIT_Purple = Color.FromArgb("#6A00FF").ToWindowsColor();
How can I load the colors that are in ./Styles/Colors.xaml
from the WinUI platform-specific code please? Both in the App.xaml
+ the App.xaml.cs
.