Files

99 lines
3.5 KiB
C#

using System;
using HelloWorld.Core;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation.Regions;
using Prism.Dialogs;
namespace HelloWorld.ViewModels
{
public class MainWindowViewModel : BindableBase
{
private string _title = "Prism Application";
private readonly IDialogService _dialogService;
private readonly IRegionManager _regionManager;
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
public DelegateCommand ShowDialogCommand { get; private set; }
private DelegateCommand<string> _navigate;
public DelegateCommand<string> NavigateCommand =>
_navigate ?? (_navigate = new DelegateCommand<string>(ExecuteNavigateCommand));
void ExecuteNavigateCommand(string parameter)
{
if (!string.IsNullOrWhiteSpace(parameter))
_regionManager.RequestNavigate("ContentRegion", parameter);
}
public MainWindowViewModel(IDialogService dialogService, IRegionManager regionManager)
{
_dialogService = dialogService;
_regionManager = regionManager;
ShowDialogCommand = new DelegateCommand(ShowDialog);
}
private void ShowDialog()
{
var message = "This is a message that should be shown in the dialog.";
//using the dialog service as-is
//_dialogService.Show("NotificationDialog", new DialogParameters($"message={message}"), r =>
//{
// if (r.Result == ButtonResult.None)
// Title = "Result is None";
// else if (r.Result == ButtonResult.OK)
// Title = "Result is OK";
// else if (r.Result == ButtonResult.Cancel)
// Title = "Result is Cancel";
// else
// Title = "I Don't know what you did!?";
//});
//using custom extenions methods to simplify the app's dialogs
//_dialogService.ShowNotification(message, r =>
//{
// if (r.Result == ButtonResult.None)
// Title = "Result is None";
// else if (r.Result == ButtonResult.OK)
// Title = "Result is OK";
// else if (r.Result == ButtonResult.Cancel)
// Title = "Result is Cancel";
// else
// Title = "I Don't know what you did!?";
//});
//_dialogService.ShowConfirmation(message, r =>
//{
// if (r.Result == ButtonResult.None)
// Title = "Result is None";
// else if (r.Result == ButtonResult.OK)
// Title = "Result is OK";
// else if (r.Result == ButtonResult.Cancel)
// Title = "Result is Cancel";
// else
// Title = "I Don't know what you did!?";
//});
_dialogService.ShowNotificationInAnotherWindow(message, r =>
{
if (r.Result == ButtonResult.None)
Title = "Result is None";
else if (r.Result == ButtonResult.OK)
Title = "Result is OK";
else if (r.Result == ButtonResult.Cancel)
Title = "Result is Cancel";
else
Title = "I Don't know what you did!?";
});
}
}
}