■ Shell 엘리먼트의 BackButtonBehavior 속성을 사용해 뒤로가기 버튼 동작을 설정하는 방법을 보여준다.
▶ MonkeyDetailPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MonkeyDetailPage" x:Name="contentPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" Title="Monkey Detail Page" BackgroundColor="White" BindingContext="{x:Reference contentPage}"> <Shell.BackButtonBehavior> <BackButtonBehavior IconOverride="dotnet_bot.png" Command="{Binding BackButtonCommand}" /> </Shell.BackButtonBehavior> <StackLayout> <Label x:Name="label" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Text="MONKEY DETAIL PAGE" /> </StackLayout> </ContentPage> |
▶ MonkeyDetailPage.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 67 68 69 70 71 72 73 74 75 76 77 78 79 |
using System.Windows.Input; using TestProject.Models; namespace TestProject; /// <summary> /// 원숭이 페이지 /// </summary> [QueryProperty(nameof(Monkey), "monkey")] public partial class MonkeyDetailPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 뒤로가기 버튼 명령 - BackButtonCommand /// <summary> /// 뒤로가기 버튼 명령 /// </summary> public ICommand BackButtonCommand { get; private set; } = new Command ( () => { Shell.Current.Navigation.PopAsync(); } ); #endregion #region 원숭이 - Monkey /// <summary> /// 원숭이 /// </summary> public MonkeyModel Monkey { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MonkeyDetailPage() /// <summary> /// 생성자 /// </summary> public MonkeyDetailPage() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 표시시 처리하기 - OnAppearing() /// <summary> /// 표시시 처리하기 /// </summary> protected override void OnAppearing() { base.OnAppearing(); if(Monkey != null) { this.label.Text = $"MONKEY DETAIL PAGE : {Monkey.Name}, {Monkey.Time:HH:mm:ss}"; } else { this.label.Text = "MONKEY DETAIL PAGE"; } } #endregion } |