IController
using Microsoft.Practices.Prism.Events; using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Unity; namespace SC.UI { public interface IController : ISingletonDependency { void SubscribeEvents(); void UnsubscribeEvents(); IUnityContainer UnityContainer { get; set; } IRegionManager RegionManager { get; set; } IEventAggregator EventAggregator { get; set; } void AttachView(IViewModel viewModel); void RemoveView(IViewModel viewModel); void AttachView(string zoneName, IViewModel viewModel); void RemoveView(string zoneName, IViewModel viewModel); } }
Controller
using Microsoft.Practices.Prism.Events; using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Unity; namespace SC.UI { public abstract class Controller : NotificationObject, IController { public Controller( IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer) { RegionManager = regionManager; EventAggregator = eventAggregator; UnityContainer = unityContainer; } public IUnityContainer UnityContainer { get; set; } public IRegionManager RegionManager { get; set; } public IEventAggregator EventAggregator { get; set; } public virtual void SubscribeEvents() { } public virtual void UnsubscribeEvents() { } public void AttachView(IViewModel viewModel) { AttachView(RegionNames.MainRegion, viewModel); } public void AttachView(string regionName, IViewModel viewModel) { var zone = RegionManager.Regions[regionName]; if (null != zone && !zone.Views.Contains(viewModel)) { zone.Add(viewModel); } } public void RemoveView(IViewModel viewModel) { RemoveView(RegionNames.MainRegion, viewModel); } public void RemoveView(string regionName, IViewModel viewModel) { var region = RegionManager.Regions[regionName]; if (null != region && region.Views.Contains(viewModel)) { region.Remove(viewModel); } } } }
ModuleBase
using Microsoft.Practices.Prism.Events; using Microsoft.Practices.Prism.Modularity; using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Unity; namespace SC.UI { public class ModuleBase : IModule { protected IUnityContainer UnityContainer { get; private set; } protected IEventAggregator EventAggregator { get; private set; } protected IRegionManager RegionManager { get; private set; } public ModuleBase( IUnityContainer unityContainer, IEventAggregator eventAggregator, IRegionManager regionManager) { UnityContainer = unityContainer; EventAggregator = eventAggregator; RegionManager = regionManager; } public void Initialize() { ConfigureContainer(); InitializeModule(); SubscribeEvents(); } protected virtual void ConfigureContainer() { } protected virtual void InitializeModule() { } protected virtual void SubscribeEvents() { } protected virtual void UnSubscribeEvents() { } } }
IViewModel
using System.ComponentModel; namespace SC.UI { public interface IViewModel : INotifyPropertyChanged, ISingletonDependency { } }
ViewModelBase
namespace SC.UI { public class ViewModelBase : NotificationObject, IViewModel { public ViewModelBase() { } } }
ISingletonDependency
namespace SC.UI { public interface ISingletonDependency { } }
http://files.cnblogs.com/files/zisezhixin/SC.UI.zip
时间: 2024-10-17 15:48:24