■ MAUI 테스트 예제를 만드는 방법을 보여준다.
▶ 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 35 36 37 |
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>() .ConfigureFonts ( fontCollection => { fontCollection.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); } ); return builder.Build(); } #endregion } |
▶ App.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<Application x:Class="TestProject.App" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TestProject"> <Application.Resources> <ResourceDictionary> <Color x:Key="PrimaryColor">#512bdf</Color> <Color x:Key="SecondaryColor">White</Color> <Style TargetType="Label"> <Setter Property="FontFamily" Value="OpenSansRegular" /> <Setter Property="TextColor" Value="{DynamicResource PrimaryColor}" /> </Style> <Style TargetType="Button"> <Setter Property="Padding" Value="14,10" /> <Setter Property="BackgroundColor" Value="{DynamicResource PrimaryColor}" /> <Setter Property="FontFamily" Value="OpenSansRegular" /> <Setter Property="TextColor" Value="{DynamicResource SecondaryColor}" /> </Style> </ResourceDictionary> </Application.Resources> </Application> |
▶ App.xaml.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 |
namespace TestProject; /// <summary> /// 앱 /// </summary> public partial class App : Application { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - App() /// <summary> /// 생성자 /// </summary> public App() { InitializeComponent(); MainPage = new MainPage(); } #endregion } |
▶ MainPage.xaml
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 35 36 37 38 39 40 41 42 43 |
<?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="{DynamicResource SecondaryColor}"> <ScrollView> <Grid RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,*" Padding="{OnPlatform iOS='30,60,30,30', Default='30'}"> <Label Grid.Row="0" HorizontalOptions="Center" SemanticProperties.HeadingLevel="Level1" FontSize="32" Text="헬로우, 월드!" /> <Label Grid.Row="1" HorizontalOptions="Center" SemanticProperties.HeadingLevel="Level1" SemanticProperties.Description="Welcome to dot net Multi platform App U I" FontSize="16" Text=".NET 다중 플랫폼 앱 UI에 오신 것을 환영합니다." /> <Label x:Name="counterLabel" Grid.Row="2" HorizontalOptions="Center" FontSize="18" FontAttributes="Bold" Text="현재 카운트 : 0" /> <Button Grid.Row="3" HorizontalOptions="Center" SemanticProperties.Hint="클릭 횟수를 계산합니다." FontAttributes="Bold" Text="클릭해 주세요" Clicked="countButton_Clicked" /> <Image Grid.Row="4" HorizontalOptions="Center" WidthRequest="250" HeightRequest="310" SemanticProperties.Description="손을 흔드는 귀여운 닷넷봇!" Source="dotnet_bot.png" /> </Grid> </ScrollView> </ContentPage> |
▶ MainPage.xaml.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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 카운트 /// </summary> private int count = 0; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 카운트 버튼 클릭시 처리하기 - countButton_Clicked(sender, e) /// <summary> /// 카운트 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void countButton_Clicked(object sender, EventArgs e) { this.count++; this.counterLabel.Text = $"현재 카운트 : {count}"; SemanticScreenReader.Announce(counterLabel.Text); } #endregion } |