I want to make a label appear the same size proportionally regardless of the resolution of the target device
I have the following code
<StackLayout
Orientation="Vertical" Margin="0,0,0,0" Padding="0,0,0,0"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label Text="{Binding AccountName}"
Style="{StaticResource labelStylePrimaryBold}"
HorizontalOptions="StartAndExpand" />
</StackLayout>
I have the above code and this in my App.xaml
<Style x:Key="labelStylePrimaryBold" TargetType="Label">
<Setter Property="TextColor" Value="#414042" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="FontSize" Value="15" />
</Style>
I need to make this available across my app, I've seen the following code on https://developer.xamarin.com/guides/xamarin-forms/user-interface/text/fonts/
label.FontSize = Device.OnPlatform (
24,
Device.GetNamedSize (NamedSize.Medium, label),
Device.GetNamedSize (NamedSize.Large, label)
);
But my label does not have an ID, how would I go about linking this up?
I'm very new to Xamarin, but this seems like a fairly obvious thing to want to do.
You can use Xamarin forms NamedSize Enumeration
You can choose from:
Example:
<Label FontSize="small" Text="Joe"></Label>
<Label FontSize="Large" Text="Joe"></Label>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.