I defined an OnPlatform style of type x:Double in my main Styles.xaml which I want to use for defining different font sizes per platform. The problem is when I want to call the resource via the specified x:Key the font size of the label does not change.
My Styles.xaml file:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:ClientApp.Source.Controls"
xmlns:views="clr-namespace:ClientApp.Source.Views">
<OnPlatform x:Key="TinyFontSize" x:TypeArguments="x:Double">
<On Platform="Default" Value="12" />
</OnPlatform>
...
In a ContentPage I created following label:
...
<Label FontSize="{StaticResource TinyFontSize}" Text="Test" WidthRequest="200"/>
...
but the font size of the label does not change to size 12 only when I replace {StaticResource TinyFontSize} with a numeric value.
When I create following resource in the Styles.xaml file:
<x:Double x:Key="SmallFontSize">13</x:Double>
it would work fine but then I can not change the value depending on the operating system from the main Styles.xaml
I found a example on github in the eShop repository:
https://github.com/dotnet/eShop/blob/main/src/ClientApp/Views/CheckoutView.xaml
But even when I checkout this project and run the ClientApp it does not work…
Using:
net8.0
Microsoft.Maui.Controls (8.0.21)
Phil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.