첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.08MB

▶ HSLColorExtension.cs

namespace TestProject;

/// <summary>
/// HSL 색상 확장
/// </summary>
public class HSLColorExtension : IMarkupExtension<Color>
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Property
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region H - H

    /// <summary>
    /// H
    /// </summary>
    public float H { get; set; }

    #endregion
    #region S - S

    /// <summary>
    /// S
    /// </summary>
    public float S { get; set; }

    #endregion
    #region L - L

    /// <summary>
    /// L
    /// </summary>
    public float L { get; set; }

    #endregion
    #region A - A

    /// <summary>
    /// A
    /// </summary>
    public float A { get; set; } = 1.0f;

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 값 제공하기 - ProvideValue(serviceProvider)

    /// <summary>
    /// 값 제공하기
    /// </summary>
    /// <param name="serviceProvider">서비스 제공자</param>
    /// <returns>값</returns>
    public Color ProvideValue(IServiceProvider serviceProvider)
    {
        return Color.FromHsla(H, S, L, A);
    }

    #endregion
    #region 값 제공하기 - IMarkupExtension.ProvideValue(serviceProvider)

    /// <summary>
    /// 값 제공하기
    /// </summary>
    /// <param name="serviceProvider">서비스 제공자</param>
    /// <returns>값</returns>
    object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
    {
        return (this as IMarkupExtension<Color>).ProvideValue(serviceProvider);
    }

    #endregion
}

 

728x90

 

▶ MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:TestProject">
    <ContentPage.Resources>
        <Style TargetType="BoxView">
            <Setter Property="HorizontalOptions" Value="Center" />
            <Setter Property="VerticalOptions"   Value="Center" />
            <Setter Property="WidthRequest"      Value="80"     />
            <Setter Property="HeightRequest"     Value="80"     />
        </Style>
    </ContentPage.Resources>
    <StackLayout
        HorizontalOptions="Center"
        VerticalOptions="Center">
        <BoxView>
            <BoxView.Color>
                <local:HSLColorExtension H="0" S="1" L="0.5" A="1" />
            </BoxView.Color>
        </BoxView>
        <BoxView Margin="0,10,0,0">
            <BoxView.Color>
                <local:HSLColor H="0.33" S="1" L="0.5" />
            </BoxView.Color>
        </BoxView>
        <BoxView
            Margin="0,10,0,0"
            Color="{local:HSLColorExtension H=0.67, S=1, L=0.5}" />
        <BoxView
            Margin="0,10,0,0"
            Color="{local:HSLColor H=0, S=0, L=0.5}" />
        <BoxView
            Margin="0,10,0,0"
            Color="{local:HSLColor A=0.5}" />
    </StackLayout>
</ContentPage>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요