次の方法で共有


Element 拡張機能

Element 拡張機能には、Element のパディング、効果、フォント属性、動的リソース、テキスト、テキストの色の構成をサポートする、一連の拡張メソッドが用意されています。

Padding

Padding メソッドでは、IPaddingElementPadding プロパティを設定します。

次の例では、Paddingnew Thickness(5, 10) に設定します。

new Button().Padding(5, 10);

次の例では、Paddingnew Thickness(10, 20, 30, 40) に設定します。

new Button().Padding(new Thickness(10, 20, 30, 40));
new Button().Paddings(10, 20, 30, 40);

RemoveDynamicResources

RemoveDynamicResources メソッドでは、指定された BindableObjectからすべての動的リソースを削除します。

次の例では、DynamicResourceBackgroundColorPropertyTextColorProperty から削除します。

var button = new Button().DynamicResources(
    (Button.BackgroundColorProperty, "ButtonBackgroundColor"),
    (Button.TextColorProperty, "ButtonTextColor"));

button.RemoveDynamicResources(Button.BackgroundColorProperty, Button.TextColorProperty);

エフェクト

Effects メソッドは、指定された EffectElement に添付します。

次の例では、ShadowEffectTouchEffectElement に添付します。

new Button().Effects(new ShadowEffect(), new TouchEffect());

フォント サイズ

FontSize メソッドでは、IFontElement 要素に FontSize プロパティを設定します。

次の例では、FontSize12 に設定します。

new Button().FontSize(12);

太字

Bold メソッドでは、IFontElement 要素に FontAttributes = FontAttributes.Bold を設定します。

次の例では、ボタンのフォントを太字に設定します。

new Button().Bold()

Normal

Italic メソッドでは、IFontElement 要素に FontAttributes = FontAttributes.Italic を設定します。

次の例では、ボタンのフォントをイタリックに設定します。

new Button().Italic()

Font

Font メソッドでは、IFontElement 要素に FontFamilyFontSizeFontAttributes を設定します。

次の例では、ボタンのフォントをイタリックに設定します。

new Button().Font(family: "OpenSansRegular", size: 12.5, bold: true, italic: true);

TextColor

TextColor メソッドでは、ITextStyle 要素に TextColor プロパティを設定します。

次の例では、TextColorColors.Green に設定します。

new Button().TextColor(Colors.Green);

Text

Text メソッドでは、IText 要素に Text プロパティを設定します。

次の例では、Text"Tap Here" に設定します。

new Button().Text("Tap Here");

次の例では、Text"Tap Here" に設定し、TextColor プロパティを Colors.Blue に設定します。

new Button().Text("Tap Here", Colors.Blue);