Elementtillägg

De Element tilläggen innehåller en serie tilläggsmetoder som stöder konfiguration av utfyllnad, effekter, teckensnittsattribut, dynamiska resurser, text och textfärg för en Element.

Utfyllnad

Metoden Padding anger Padding egenskapen för alla element som stöder utfyllnad: Border, Button, ContentPresenter, ImageButton, Label, Layout, Page, ScrollViewoch TemplatedView.

I följande exempel anges Padding till new Thickness(5, 10):

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

Följande exempel ställer in Paddingnew Thickness(10, 20, 30, 40):

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

Ta bort dynamiska resurser

Metoden RemoveDynamicResources tar bort alla dynamiska resurser från en angiven Element.

Följande exempel tar DynamicResource bort från BackgroundColorProperty och TextColorProperty:

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

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

Effekter

Metoden Effects kopplar den angivna Effect till en Element.

I följande exempel kopplas ShadowEffect och TouchEffect till Element:

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

Fontstorlek

Metoden FontSize anger egenskapen för FontSize ett ITextStyle element.

I följande exempel anges FontSize till 12:

new Button().FontSize(12);

Fet

Metoden Bold ställer in FontAttributes = FontAttributes.Bold på ett ITextStyle-element.

I följande exempel anges knappteckensnittet till fetstil:

new Button().Bold()

Kursiv

Metoden Italic ställer in FontAttributes = FontAttributes.Italic på ett ITextStyle-element.

I följande exempel anges knappteckensnittet till kursivt:

new Button().Italic()

Teckensnitt

Metoden Font anger FontFamily, FontSizeoch FontAttributes på ett ITextStyle element.

I följande exempel anges knappteckensnittet till kursivt:

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

Textfärg

Metoden TextColor anger egenskapen för TextColor ett ITextStyle element.

I följande exempel anges TextColor till Colors.Green:

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

Text

Metoderna Text anger egenskapen för Text ett IText element.

I följande exempel anges Text till "Tap Here":

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

I följande exempel anges Text till "Tap Here" och egenskapen TextColor anges till Colors.Blue:

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