[C#/MAUI/.NET6] Shell 클래스 : GoToAsync 메소드 사용시 객체 기반 쿼리 매개 변수 전달하기 (QueryPropertyAttribute 클래스 사용)
C#/MAUI 2022. 5. 4. 12:32728x90
반응형
728x170
▶ MonkeyModel.cs
namespace TestProject.Models
{
/// <summary>
/// 원숭이 모델
/// </summary>
public class MonkeyModel
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 명칭 - Name
/// <summary>
/// 명칭
/// </summary>
public string Name { get; set; }
#endregion
#region 시간 - Time
/// <summary>
/// 시간
/// </summary>
public DateTime Time { get; set; }
#endregion
}
}
728x90
▶ MonkeyPage.xaml.cs
using TestProject.Models;
namespace TestProject;
/// <summary>
/// 원숭이 페이지
/// </summary>
public partial class MonkeyPage : ContentPage
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MonkeyPage()
/// <summary>
/// 생성자
/// </summary>
public MonkeyPage()
{
InitializeComponent();
this.detailButton.Clicked += detailButton_Clicked;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 원숭이 상세 버튼 클릭시 처리하기 - detailButton_Clicked(sender, e)
/// <summary>
/// 원숭이 상세 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private async void detailButton_Clicked(object sender, EventArgs e)
{
MonkeyModel monkey = new MonkeyModel
{
Name = "홍길동",
Time = DateTime.Now
};
Dictionary<string, object> dictionary = new Dictionary<string, object>
{
{ "monkey", monkey }
};
await Shell.Current.GoToAsync($"//동물/원숭이/원숭이상세", dictionary);
}
#endregion
}
300x250
▶ MonkeyDetailPage.xaml.cs
using TestProject.Models;
namespace TestProject;
/// <summary>
/// 원숭이 페이지
/// </summary>
[QueryProperty(nameof(Monkey), "monkey")]
public partial class MonkeyDetailPage : ContentPage
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#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
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요