Device.Stylesを使用すると、あらかじめ決められた組み込みスタイルを使用することができます。
以下に例を示します。
はじめに書くスタイルをかくにんできるようにLabelを6つ配置しておきます。
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:DevuceClassSapmle3"
x:Class="DevuceClassSapmle3.MainPage">
<StackLayout Padding="10, 30, 10, 10">
<Label x:Name="label1" Text="Welcome Xamarin Forms!"
VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="label2" Text="Welcome Xamarin Forms!"
VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="label3" Text="Welcome Xamarin Forms!"
VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="label4" Text="Welcome Xamarin Forms!"
VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="label5" Text="Welcome Xamarin Forms!"
VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="label6" Text="Welcome Xamarin Forms!"
VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
つづいて、各LabelのStyleプロパティに組み込みスタイルの値を設定します。
public MainPage()
{
InitializeComponent();
label1.Style = Device.Styles.BodyStyle;
label2.Style = Device.Styles.CaptionStyle;
label3.Style = Device.Styles.ListItemDetailTextStyle;
label4.Style = Device.Styles.ListItemTextStyle;
label5.Style = Device.Styles.TitleStyle;
label6.Style = Device.Styles.SubtitleStyle;
}
上記例のように、組み込みスタイルを使用すると、各プラットフォームで適切なスタイルが設定されるようになります。
実行例を以下に示します。
Please follow and like us:



コメント