C#/Xamarin Maui
[.NET MAUI] DisplayPromptAsync 사용하기 - ViewModel
kjun
2022. 9. 15. 12:35
728x90
728x170
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
![](https://blog.kakaocdn.net/dn/mRy9e/btrL9abWSvq/GRZB64IPYnMvexIzfKGukk/img.gif)
Android
![](https://blog.kakaocdn.net/dn/uXTXJ/btrMcPEcASf/xF61CcdsJBNRRunjUtEjK0/img.gif)
728x90
그리드형