-
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathDialogExtensionPageViewModel.cs
More file actions
61 lines (52 loc) · 1.64 KB
/
DialogExtensionPageViewModel.cs
File metadata and controls
61 lines (52 loc) · 1.64 KB
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
using System;
using System.Threading.Tasks;
using Prism.Commands;
using Prism.Dialogs;
namespace PrismSample.ViewModels
{
public class DialogExtensionPageViewModel : BaseViewModel
{
private readonly IDialogService _dialogService;
public DialogExtensionPageViewModel(IDialogService dialogService)
{
Title = "Dialog Service Extension";
_dialogService = dialogService;
GetNameCommand = new DelegateCommand(OnGetNameTapped);
}
private string _name;
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
}
public DelegateCommand GetNameCommand { get; }
private async void OnGetNameTapped()
{
// Option A - Use generic extension
//Name = await GetNameExtAsync();
// Option B - Use type extension
Name = await GetNameAsync();
}
private async Task<string> GetNameExtAsync()
{
var r = await _dialogService.ShowDialogAsync("NameDialog");
return r.Parameters.GetValue<string>("Name");
}
private Task<string> GetNameAsync()
{
var tcs = new TaskCompletionSource<string>();
try
{
_dialogService.ShowDialog("NameDialog", new DialogParameters(), (dparams) =>
{
tcs.SetResult(dparams.Parameters.GetValue<string>("Name"));
});
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
return tcs.Task;
}
}
}