■ Popup 엘리먼트를 사용해 팝업을 표시하는 방법을 보여준다.
▶ 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 |
<?xml version="1.0" encoding="utf-8" ?> <toolkit:Popup x:Class="TestProject.CustomPopup" 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" HorizontalOptions="Center" VerticalOptions="Center" Color="White" CanBeDismissedByTappingOutsideOfPopup="True"> <Grid WidthRequest="300" HeightRequest="400"> <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10"> <Label HorizontalOptions="Center" FontSize="24" Text="샘플 팝업 입니다." /> <HorizontalStackLayout HorizontalOptions="Center" Margin="10"> <Button x:Name="okButton" HorizontalOptions="Center" Text="확인" /> <Button x:Name="cancelButton" Margin="10,0,0,0" HorizontalOptions="Center" Text="취소" /> </HorizontalStackLayout> </VerticalStackLayout> </Grid> </toolkit:Popup> |
▶ 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 58 59 60 61 |
using CommunityToolkit.Maui.Views; namespace TestProject; /// <summary> /// 커스텀 팝업 /// </summary> public partial class CustomPopup : Popup { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomPopup() /// <summary> /// 생성자 /// </summary> public CustomPopup() { InitializeComponent(); ResultWhenUserTapsOutsideOfPopup = "외부"; this.okButton.Clicked += okButton_Clicked; this.cancelButton.Clicked += cancelButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 확인 버튼 클릭시 처리하기 - okButton_Clicked(sender, e) /// <summary> /// 확인 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void okButton_Clicked(object sender, EventArgs e) { Close("확인"); } #endregion #region 취소 버튼 클릭시 처리하기 - cancelButton_Clicked(sender, e) /// <summary> /// 취소 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void cancelButton_Clicked(object sender, EventArgs e) { Close("취소"); } #endregion } |
▶ 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 38 39 40 41 42 |
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 } |