Issue
Is there are way to create a custom fontsize that would work the same as Micro or Small or Title that are already built into Xamarin. I want to be able to use it like the following:
<Label Text="Test" FontSize="MyFontSize"/>
I think it would be implemented something like the following inside my resource dictionary but it isn't working:
<FontSize x:Key="MyFontSize">
<OnPlatform x:TypeArguments="FontSize">
<On Platform="UWP">25</On>
<On Platform="iOS">12</On>
</OnPlatform>
</FontSize>
The error says:
"The type FontSize can not be found"
It's not a runtime error. It's just a green underline in the XAML editor.
Can it be done?
Solution
You need to use x:Double
instead:
<OnPlatform x:Key="MyFontSize" x:TypeArguments="x:Double">
<On Platform="UWP">25</On>
<On Platform="iOS">12</On>
</OnPlatform>
And then reference the resource like this:
<Label Text="Test" FontSize="{StaticResource MyFontSize}"/>
Or you can specify it directly on the view:
<Label Text="Test">
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="UWP">25</On>
<On Platform="iOS">12</On>
</OnPlatform>
</Label.FontSize>
</Label>
Answered By - Martin Zikmund Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.