첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ ColorToColorForTextConverter 클래스를 사용해 배경 색상에서 텍스트 색상을 구하는 방법을 보여준다.

TestProject.zip
0.15MB

▶ 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"
    BackgroundColor="White">
    <Label x:Name="label"
        HorizontalOptions="Center"
        VerticalOptions="Center"
        Text="테스트 문자열 입니다." />
</ContentPage>

 

▶ MauiProgram.cs

using CommunityToolkit.Maui.Converters;

namespace TestProject;

/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - MainPage()

    /// <summary>
    /// 생성자
    /// </summary>
    public MainPage()
    {
        InitializeComponent();

        ColorToColorForTextConverter converter = new ColorToColorForTextConverter();

        this.label.SetBinding
        (
            Label.TextColorProperty,
            new Binding("BackgroundColor", source : this, converter : converter)
        );
    }

    #endregion
}
728x90
그리드형(광고전용)
Posted by icodebroker
,