[C#/MAUI/.NET6] ColorToColorForTextConverter 엘리먼트 : 배경 색상 → 텍스트 색상 변환자 사용하기
C#/MAUI 2022. 7. 20. 18:17728x90
반응형
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"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
BackgroundColor="White">
<ContentPage.Resources>
<toolkit:ColorToColorForTextConverter x:Key="ColorToColorForTextConverterKey" />
</ContentPage.Resources>
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
TextColor="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BackgroundColor, Converter={StaticResource ColorToColorForTextConverterKey}}"
Text="테스트 문자열 입니다." />
</ContentPage>
▶ MauiProgram.cs
using CommunityToolkit.Maui;
namespace TestProject;
/// <summary>
/// MAUI 프로그램
/// </summary>
public static class MauiProgram
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region MAUI 앱 생성하기 - CreateMauiApp()
/// <summary>
/// MAUI 앱 생성하기
/// </summary>
/// <returns>MAUI 앱</returns>
public static MauiApp CreateMauiApp()
{
MauiAppBuilder builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts
(
fontCollection =>
{
fontCollection.AddFont("OpenSans-Regular.ttf" , "OpenSansRegular" );
fontCollection.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
}
);
return builder.Build();
}
#endregion
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요