1、在Common文件夹下新建文件夹Events,新建扩展类UpdateLoadingEvent
public class UpdateModel {public bool IsOpen { get; set; }}internal class UpdateLoadingEvent : PubSubEvent<UpdateModel>{}
2、新建一个静态扩展类DialogExtensions来编写注册和推送等待消息弹框方法
public static class DialogExtensions{/// <summary>/// 推送等待消息/// </summary>/// <param name="aggregator"></param>/// <param name="model"></param>public static void UpdateLoading(this IEventAggregator aggregator, UpdateModel model){aggregator.GetEvent<UpdateLoadingEvent>().Publish(model);}/// <summary>/// 注册等待消息/// </summary>/// <param name="aggregator"></param>/// <param name="model"></param>public static void Register(this IEventAggregator aggregator, Action<UpdateModel> model){aggregator.GetEvent<UpdateLoadingEvent>().Subscribe(model);}}
3、在ViewModel中添加实现类NavigationViewModel
public class NavigationViewModel : BindableBase, INavigationAware{private readonly IContainerProvider containerProvider;private readonly IEventAggregator aggregator;public NavigationViewModel(IContainerProvider containerProvider){this.containerProvider = containerProvider;aggregator = containerProvider.Resolve<IEventAggregator>();}