Reputation: 68800
I have defined a style , but I'd like to set the Android and iOS values to a DynamicResource - What's the syntax?
<Style
TargetType="SearchBar" ApplyToDerivedTypes="true">
<Setter Property="BackgroundColor" Value="{OnPlatform Android='White', iOS='#4F8BBF'}"/>
</Style>
Upvotes: 1
Views: 924
Reputation: 9144
Per official documentation for different values for different targets
<!-- Colors -->
<Color x:Key="AppBackgroundColor">WhiteSmoke</Color>
<Color x:Key="iOSNavigationBarColor">WhiteSmoke</Color>
<Color x:Key="AndroidNavigationBarColor">#2196F3</Color>
<Color x:Key="iOSNavigationBarTextColor">Black</Color>
<Color x:Key="AndroidNavigationBarTextColor">White</Color>
<!-- Implicit styles -->
<Style TargetType="{x:Type NavigationPage}">
<Setter Property="BarBackgroundColor"
Value="{OnPlatform iOS={StaticResource iOSNavigationBarColor},
Android={StaticResource AndroidNavigationBarColor}}" />
<Setter Property="BarTextColor"
Value="{OnPlatform iOS={StaticResource iOSNavigationBarTextColor},
Android={StaticResource AndroidNavigationBarTextColor}}" />
</Style>
<Style TargetType="{x:Type ContentPage}" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{StaticResource AppBackgroundColor}" />
</Style>
That's for setting different values
But if you are really looking for a literal dynamic resource, you'll have to set it in code behind constructor.
Resources ["searchBarStyle"] = Resources ["blueSearchBarStyle"];
Upvotes: 4