■ Snackbar 클래스의 Make 정적 메소드를 사용해 스낵바를 생성하는 방법을 보여준다. (ANDROID)
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?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"> <Grid x:Name="grid"> <Button x:Name="showButton" HorizontalOptions="Center" VerticalOptions="Center" Text="스낵바 표시하기" /> <BoxView x:Name="boxView" VerticalOptions="End" HeightRequest="0" /> </Grid> </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 58 59 60 61 62 63 64 65 66 |
using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Core; namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.showButton.Clicked += showButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 스낵바 표시 버튼 클릭시 처리하기 - showButton_Clicked(sender, e) /// <summary> /// 스낵바 표시 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void showButton_Clicked(object sender, EventArgs e) { SnackbarOptions options = new SnackbarOptions { CornerRadius = new CornerRadius(10), BackgroundColor = Colors.Blue, CharacterSpacing = 0, Font = Microsoft.Maui.Font.SystemFontOfSize(16), ActionButtonFont = Microsoft.Maui.Font.SystemFontOfSize(14), TextColor = Colors.White, ActionButtonTextColor = Colors.White }; Action action = async () => await DisplayAlert ( "INFORMATION", "사용자가 스낵바 액션 버튼을 탭했습니다.", "OK" ); ISnackbar snackbar = Snackbar.Make("스낵바 입니다.", action, "종료", TimeSpan.FromSeconds(3), options, this.boxView); await snackbar.Show(); } #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 } |