[C#/MAUI/.NET6] ColorAnimationExtensions 클래스 : TextColorTo 확장 메소드를 사용해 텍스트 색상 애니메이션 만들기
C#/MAUI 2022. 7. 29. 15:32728x90
반응형
728x170
■ ColorAnimationExtensions 클래스의 TextColorTo 확장 메소드를 사용해 텍스트 색상 애니메이션을 만드는 방법을 보여준다.
▶ MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage" x:Name="mainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<VerticalStackLayout
HorizontalOptions="Center"
VerticalOptions="Center"
Spacing="10">
<Label x:Name="label"
HorizontalOptions="Center"
FontSize="48"
FontAttributes="Bold"
TextColor="Blue"
Text="MAUI" />
<Button x:Name="testButton"
HorizontalOptions="Center"
Text="테스트" />
</VerticalStackLayout>
</ContentPage>
▶ MainPage.xaml.cs
namespace TestProject;
/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 현재 색상
/// </summary>
private Color currentColor = Colors.Blue;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
this.testButton.Clicked += testButton_Clicked;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 테스트 버튼 클릭시 처리하기 - testButton_Clicked(sender, e)
/// <summary>
/// 테스트 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private async void testButton_Clicked(object sender, EventArgs e)
{
if(this.currentColor == Colors.Blue)
{
this.currentColor = Colors.Red;
}
else
{
this.currentColor = Colors.Blue;
}
await this.label.TextColorTo(this.currentColor);
}
#endregion
}
▶ 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
반응형
그리드형(광고전용)
댓글을 달아 주세요