英文:
How to create a custom font size in xaml using Xamarin, so that you can change font sizes depending on device?
问题
Is there a 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?
英文:
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?
答案1
得分: 4
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>
英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论