■ ColorToColorForTextConverter 클래스를 사용해 배경 색상에서 텍스트 색상을 구하는 방법을 보여준다.
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 |
<?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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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 } |