Share via


스타일<T>

Style<T> 는 구성 Microsoft.Maui.Controls.Style을 지원하는 일련의 흐름 확장 메서드를 제공합니다.

생성자

Style<T> 에서는 다음 생성자를 제공합니다.

public Style(BindableProperty property, object value);
public Style(params (BindableProperty Property, object Value)[] setters);

이러한 생성자를 사용하여 다음과 같이 단일 setter에 대해 초기화 Style<T> 하고 할당할 Microsoft.Maui.Controls.Style 수 있습니다.

new Label
{
    Style = new Style<Entry>(Entry.TextColorProperty, Colors.Red)
}

이러한 생성자는 다음과 같이 형식을 사용하여 여러 setter에 대해 초기화 Style<T> 하고 할당하는 Microsoft.Maui.Controls.Style 데 사용할 수도 있습니다.

new Label
{
    Style = new Style<Entry>(
            (Entry.TextColorProperty, Colors.Red),
            (Entry.BackgroundColorProperty, Colors.White),
            (Entry.FontAttributesProperty, FontAttributes.Bold))
}

속성

Style<T> 에는 하나의 속성이 MauiStyle포함됩니다.

이 속성은 Microsoft.Maui.Controls.Style 초기화 시 활용되고 할당됩니다.

추가되고 구현된 Style<T> 스타일은 속성에 MauiStyle 저장됩니다.

public Microsoft.Maui.Controls.Style MauiStyle { get; }

메서드

Style<T>는 추가 스타일, 설정, 설정 및 설정ApplyToDerivedTypesBasedOnCanCascade에 대한 흐름 확장 메서드 Add 를 제공합니다.

추가

Style<T> 에서는 기존 스타일에 추가할 수 있는 여러 가지 방법을 제공합니다.

public Style<T> Add(BindableProperty property, object value);
public Style<T> AddAppThemeBinding(BindableProperty property, object light, object dark);
public Style<T> Add(params (BindableProperty Property, object Value)[] setters);
public Style<T> AddAppThemeBindings(params (BindableProperty Property, object Light, object Dark)[] setters);
public Style<T> Add(params Behavior[] behaviors);
public Style<T> Add(params TriggerBase[] triggers);

다음과 Add 같이 메서드를 사용할 수 있습니다.

new Label
{
    Style = new Style<Label>()
                .AddAppThemeBinding(Label.TextColorProperty, Colors.Red, Colors.Orange)
                .Add((Label.BackgroundColorProperty, Colors.White), (Label.FontAttributesProperty, FontAttributes.Bold))
                .Add(new NumericValidationBehavior())
                .Add(new EventTrigger { Event = nameof(Label.Focused) });
}

사용에 AddAppThemeBinding 대한 자세한 내용은 테마 설명서를 참조하세요.

ApplyToDerivedTypes

fluent 확장 메서드는 ApplyToDerivedTypes(bool value)속성의 AppleToDerivedTypes 값을 설정합니다.

public Style<T> ApplyToDerivedTypes(bool value);

다음과 같이 사용할 수 있습니다.

new Label
{
    Style = new Style<Label>(Label.TextColorProperty, Colors.Red)
                .ApplyToDerivedTypes(true);
}

Basedon

fluent 확장 메서드는 BasedOn(Style value)속성의 BasedOn 값을 설정합니다.

public Style<T> BasedOn(Style value);

기존 스타일을 기반으로 현재 스타일을 기반으로 다음과 같이 사용할 수 있습니다.

new VerticalStackLayout
{
    Children = 
    {
        new Label
        {
            Style = new Style<Label>(Label.TextColorProperty, Colors.Red)
        }.Assign(out Label redTextLabel),

        new Label
        {
          Style = new Style<Label>().BasedOn(redTextLabel.Style);
        }
    }
};

CanCascade

fluent 확장 메서드는 CanCascade(bool value)속성의 CanCascade 값을 설정합니다.

public Style<T> CanCascade(bool value);

다음과 같이 사용할 수 있습니다.

new Label
{
  Style = new Style<Label>(Label.TextColorProperty, Colors.Red).CanCascade(true);
}