C#/Xamarin Maui
[.NET MAUI] DisplayPromptAsync 사용하기 - ViewModel
kjun.kr
2022. 9. 15. 12:35
728x90
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Maui.ControlTest.Models;
namespace Maui.ControlTest.ViewModels
{
public class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string displayPromptText = "None";
public string DisplayPromptText
{
get
{
return displayPromptText;
}
set
{
displayPromptText = value;
NotifyPropertyChanged();
}
}
public Command DisplayPromptCommand { get; set; }
public MainViewModel()
{
DisplayPromptCommand = new Command(OnDisplayPromptCommand);
}
private async void OnDisplayPromptCommand()
{
DisplayPromptText = await Application.Current.MainPage.DisplayPromptAsync("Input Site", "\r\nWhere do you go to the site?");
}
}
}
사용자에게 입력 받을 값이 있는 경우 사용합니다.
결과
Windows

Android

728x90