I would like to use a DynamicResource in a Style for only 1 platform (f.e. Android) without having to do something in the code-behind.
I've seen a solution which works if you want to implement something for multiple platforms, but when I try to use it without one of the platforms (like the xaml below), the app crashes on a NullReferenceException when I run it on a device with a different platform (so in this example iOS).
<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{DynamicResource PageBackgroundColor}"/>
<Setter Property="Padding" Value="{OnPlatform Android={DynamicResource ContentPagePadding}}"/>
</Style>
I've also tried numeral solutions along the lines of the snippet below, which also results in a crash when I run it on a device with the same platform (so in this example Android).
<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{DynamicResource PageBackgroundColor}"/>
<Setter Property="Padding" >
<Setter.Value>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android">
<DynamicResource Key="ContentPagePadding"/>
</On>
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
So at this point I hope someone has an idea how I would be able to do this (without the app crashing instantly). But I'm afraid this (currently) isn't possible. Anyways, thanks in advance for the help.
EDIT 1: I've noticed the 2nd solution does seem to work with a static resource, but the resources I want to use are dynamic, so that isn't much of an option, though I am curious why staticresources do work and dynamic resources don't.