void IModuleManagerImplementation.OnViewModelRemoved(string regionName, ViewModelRemovedEventArgs e) { var region = GetRegion(regionName); region.Remove(e.ViewModelKey); RaiseViewModelRemovedEvent(regionName, e); }
void IModuleManager.Remove(string regionName, string key, bool raiseViewModelRemovingEvent) { if (!((IModuleManager)this).IsInjected(regionName, key)) { return; } var region = GetRegion(regionName); var vm = region.GetViewModel(key); if (vm != null && raiseViewModelRemovingEvent) { ViewModelRemovingEventArgs e = new ViewModelRemovingEventArgs(regionName, vm, key); RaiseViewModelRemovingEvent(regionName, e); if (e.Cancel) { return; } } region.Remove(key); if (vm != null) { ViewModelRemovedEventArgs e = new ViewModelRemovedEventArgs(regionName, vm, key); RaiseViewModelRemovedEvent(regionName, e); } }
void RaiseViewModelRemovedEvent(string regionName, ViewModelRemovedEventArgs e) { if (e.ViewModel != null) { GetEvents(e.ViewModel, false).Do(x => x.RaiseViewModelRemoved(this, e)); } GetEvents(regionName, false).Do(x => x.RaiseViewModelRemoved(this, e)); }
void OnWindowClosed(object sender, ViewModelRemovedEventArgs e) { if (e.ViewModelKey != Key) { return; } var serv = owner.GetUIWindowRegion(e.RegionName); owner.GetEvents(e.RegionName, true).ViewModelRemoved -= OnWindowClosed; task.SetResult(new WindowInjectionResult(e.RegionName, e.ViewModel, e.ViewModelKey, serv != null ? serv.Result : null)); dispose(this); }
void IModuleManager.Clear(string regionName) { var region = GetRegion(regionName); var vms = region.ViewModels.ToDictionary(x => region.GetKey(x), x => x); GetRegion(regionName).Clear(); foreach (var vm in vms) { ViewModelRemovedEventArgs e = new ViewModelRemovedEventArgs(regionName, vm.Value, vm.Key); RaiseViewModelRemovedEvent(regionName, e); } }