Prism&MEF构建开发框架 (三)
菜单管控模块EntityFW
菜单的加载采用MEF技术,程序实现思路:
1 .主菜单加载页面MainMenuView.xaml指向MenuRegion
2. 菜单Item点击及内容加载,采用订阅模式,即菜单item点击时发布消息,shell负责订阅并过滤加载子模块
MainMenuView.xaml
<UserControl x:Class="EntityFW.Views.MainMenuView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid x:Name="LayoutRoot" Background="White">
<ItemsControl x:Name="MenuItems" BorderBrush="Black">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<RadioButton Command="{Binding ViewMenuCommand}" CommandParameter="{Binding}" GroupName="MenuItem"
Style="{StaticResource RadioButtonStyle}" VerticalContentAlignment="Center" Height="35" Padding="15,0,0,0" Margin="2,1,2,1">
<StackPanel>
<TextBlock Text="{Binding NameFL}" FontSize="10" Foreground="Gray" />
<TextBlock Text="{Binding NameCH}" FontSize="14" />
</StackPanel>
</RadioButton>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>
后台代码实现
using EntityFW.ViewModels;
using MyGlobal.Infrustructure;
using MyGlobal.Infrustructure.Behaviors;
using MyGlobal.Infrustructure.Interfaces;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Windows.Controls;
namespace EntityFW.Views
{
/// <summary>
/// MainMenu.xaml 的交互逻辑
/// </summary>
[ViewExport(RegionName = RegionNames.MenuRegion)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public partial class MainMenuView : UserControl,IPartImportsSatisfiedNotification
{
private readonly ObservableCollection<MainMenuViewModel> _MenuList =
new ObservableCollection<MainMenuViewModel>();
[Import]
IRegionManager _regionManager;
public MainMenuView()
{
InitializeComponent();
}
public void OnReceiveNewMenu(MainMenuViewModel menu)
{
_MenuList.Insert(0, menu);
}
public void OnImportsSatisfied()
{
//模块加载成功
MainMenuViewModel mmvm = new MainMenuViewModel();
//初始化主菜单
MenuItems.ItemsSource = mmvm.InitPopMenuListData();
}
}
}
MainMenuViewModel.cs
using EntityFW.Events;
using EntityFW.Models;
using Microsoft.Practices.ServiceLocation;
using MyGlobal.Infrustructure;
using MyGlobal.Infrustructure.Events;
using MyGlobal.Infrustructure.Interfaces;
using Prism.Commands;
using Prism.Modularity;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace EntityFW.ViewModels
{
[Export(typeof(MainMenuViewModel))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class MainMenuViewModel : MyBindableBase
{
[ImportMany]
IEnumerable<Lazy<IMainMenu, IMainMenuDepict>> _MenuList = null;
LoginUser _User;
public ICollection<MainMenuViewModel> InitPopMenuListData()
{
CompositeComponents();
ICollection<MainMenuViewModel> list = new List<MainMenuViewModel>();
//判断登录用户是否有权限
foreach (var o in _MenuList.Where(item => (item.Metadata.Name != null || true)))
{
MainMenuViewModel mm = new MainMenuViewModel(o.Value.NameCH,o.Value.NameFL,o.Value.Url,o.Value.ParentUrl,o.Value.PowerKey);
mm.ViewMenuCommand = new RelayCommand<MainMenuViewModel>(OnViewMainMenu);
list.Add(mm);
}
return list;
}
public void Initialize()
{
}
void CompositeComponents()
{
var assemblylog = new AssemblyCatalog(this.GetType().Assembly);
var aggregatelog = new AggregateCatalog();
aggregatelog.Catalogs.Add(assemblylog);
aggregatelog.Catalogs.Add(new DirectoryCatalog("../../Modules"));
var container = new CompositionContainer(aggregatelog);
container.ComposeParts(this);
//var assemblylog = new AssemblyCatalog(this.GetType().Assembly);
////AppDomain.CurrentDomain.BaseDirectory + "\\Parts", "*.dll"
//var directoryCatalog = new DirectoryCatalog("../../Modules");
////var typeCatalog = new TypeCatalog(typeof(Class6), typeof(Class7));
//var aggregateCatalog = new AggregateCatalog(assemblylog, directoryCatalog);
//var _container = new CompositionContainer(aggregateCatalog);
//var exports = _container.GetExports<object>();
//string x = "";
//foreach (var exportValue in exports)
//{
// // x += exportValue.Value.GetType().ToString();
// Console.WriteLine(exportValue.Value.GetType());
//}
}
public string ModuleName
{
get { return "MainMenu"; }
}
public ICommand ViewMenuCommand { get; private set; }
public MainMenuViewModel() : base("", "", "", "", 1) { }
[ImportingConstructor]
public MainMenuViewModel(string chName, string flName, string url, string parentUrl, int powerKey)
: base(chName, flName, url, parentUrl, powerKey)
{
_User = new LoginUser();
}
public void OnViewMainMenu(MainMenuViewModel obj)
{
//发布消息
EventAggregatorRepository.EventAggregator
.GetEvent<ViewMainMenuEvent>()
.Publish(obj);
//string x = new Uri(obj.ViewUri, UriKind.Relative).AbsolutePath;
// _regionManager.RequestNavigate(RegionNames.MCWrapRegion, new Uri(obj.ViewUri, UriKind.Relative));
}
/****************************************/
string _MenuName;
public string MenuName
{
get
{
return _MenuName;
}
set
{
base.SetProperty(ref _MenuName, value);
}
}
string _ViewUri;
public string ViewUri
{
get
{
return _ViewUri;
}
set
{
base.SetProperty(ref _ViewUri, value);
}
}
}
}
Prism&MEF构建开发框架 (三)的更多相关文章
- Prism&MEF构建开发框架 (一)
Shell框架XECA shell.xaml主要起到是一个容器或壳的作用 <Window x:Class="XECA.Shell" xmlns="http ...
- Prism&MEF构建开发框架
系统框架构想效果图 平台简单由左侧菜单和右侧内容区以及顶部系统和用户信息区构成 菜单根据系统模块动态加载 右侧,根据左侧选中菜单动态加载子模块,子模块集合以tab选项卡方式布局 系统模块划分为Shel ...
- 一步步实现 Prism + MEF(一)--- 搭建框架
第一步:构建一个名为Bootstrapper的类作为引导程序. class Bootstrapper : MefBootstrapper { } 第二步:在MainWindow窗体中添加一个Coont ...
- Prism 文档 第三章 管理组件之间的依赖关系
第3章:管理组件之间的依赖关系 基于Prism库的复合应用程 ...
- Xamarin+Prism开发详解三:Visual studio 2017 RC初体验
Visual studio 2017 RC出来一段时间了,最近有时间就想安装试试,随带分享一下安装使用体验. 1,卸载visual studio 2015 虽然可以同时安装visual studio ...
- UWP应用程序使用Prism框架构建MVVM
在我们创建的UWP解决方案中选择引用->管理NuGet包程序包 NuGet管理包 2. 搜索Prism.Core,并安装 搜索Prism.Core 3. 搜索Prism.Unity,并安装 搜索 ...
- Docker基本命令与使用 —— Dockerfile指令与构建(三)
一.Dockerfile指令上 1.指令格式 # Comment 注释, 以#开头 INSTRUCTION argument 以大写的指令+参数 #First Dockerfile 注释 FROM u ...
- 一步步实现 Prism + MEF(二)--- 绑定命令
Prism程序集为我们提供了DelegateCommand命令,使用该命令可实现窗口直接绑定.第一步:在ViewModel中定义一个DelegateCommand属性. public Delegate ...
- S3C6410嵌入式应用平台构建(三)
构建了好久的系统,由于工作原因,没有及时写记录,目前我已经进展到构建yaffs2文件系统,启动Linux内核了.Uboot移植基本功能已经完成. 由于Uboot移植方法大致是一样的,我主要参考这位博友 ...
随机推荐
- js:数据结构笔记13--检索算法
顺序查找:也称线性查找,暴力查找的一种 基本格式: var nums = []; for(var i = 0; i < 10; ++i) { nums[i] = Math.floor(Math. ...
- HDU3729 I'm Telling the Truth(字典序最大的最大流)
题目大概说n个学生,都各自有一个互不相同的成绩排名,他们各自说了他们成绩排名所在区间,问最多有几个学生没说谎以及字典序最大的没说谎的学生序列. 学生作为一个X部的点,排名作为Y部的点,学生与其成绩排名 ...
- js html5推送 实例
<!DOCTYPE html> <html> <head> <title>Simple Webkit notification exampl ...
- linux fork 进程后 主进程的全局变量
fork一个进程后,复制出来的task_struct结构与系统的堆栈空间是父进程独立的,但其他资源却是与父进程共享的,比如文件指针,socket描述符等 不同的进程使用不同的地址空间,子进程被创建后, ...
- fetch API
一.什么是fetch? fetch的作用类似于XMLHttpRequet的作用,用于异步请求网络,其提供的API更加的完善. fetch提供了Request和Response对象的定义,用于自定义网络 ...
- Ubuntu 循环遍历当前目录下所有文本文件中的字符
sudo grep -n 'xxxx' -r ./*
- .NET Framework 4.5 的五大特性
介绍 从.NET4.5发布到现在已经有一年多了.但问题是针对最近微软发布的版本信息中,大部分的.NET开发人员所讨论交流的只是其中的一两个特性.其他的特性仅仅停留在MSDN中或者沦为简介文档.例如:现 ...
- [转]3天搞定的小型B/S内部管理类软件定制开发项目【软件开发实战10步骤详解】
本文转自:http://www.cnblogs.com/jirigala/archive/2010/10/07/1845275.html 2010-10-07 21:39 by 通用C#系统架构, 5 ...
- 【iHMI43 应用演示】之 modbus 协议(从机)通信演示
============================== 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:h ...
- CKEditor的使用-编辑文本
官网下载以及演示:http://ckeditor.com/ 引入js <script src="/Example6/ckeditor/ckeditor.js">< ...