You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
downkyi/DownKyi/ViewModels/BaseViewModel.cs

59 lines
1.6 KiB

using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Windows;
namespace DownKyi.ViewModels
{
public class BaseViewModel : BindableBase, INavigationAware
{
protected readonly IEventAggregator eventAggregator;
protected readonly IDialogService dialogService;
protected string ParentView = string.Empty;
public BaseViewModel(IEventAggregator eventAggregator)
{
this.eventAggregator = eventAggregator;
}
public BaseViewModel(IEventAggregator eventAggregator, IDialogService dialogService)
{
this.eventAggregator = eventAggregator;
this.dialogService = dialogService;
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public virtual void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public virtual void OnNavigatedTo(NavigationContext navigationContext)
{
string viewName = navigationContext.Parameters.GetValue<string>("Parent");
if (viewName != null)
{
ParentView = viewName;
}
}
/// <summary>
/// 异步修改绑定到UI的属性
/// </summary>
/// <param name="callback"></param>
protected void PropertyChangeAsync(Action callback)
{
if (Application.Current == null) { return; }
Application.Current.Dispatcher.Invoke(callback);
}
}
}