[C#/MAUI/.NET6] ColorToColorForTextConverter 클래스 : 배경 색상 → 텍스트 색상 변환자 사용하기
C#/MAUI 2022. 7. 20. 18:28728x90
728x170
■ ColorToColorForTextConverter 클래스를 사용해 배경 색상에서 텍스트 색상을 구하는 방법을 보여준다.
▶ 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
그리드형(광고전용)