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移植方法大致是一样的,我主要参考这位博友 ...
随机推荐
- 17111 Football team
时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题 语言: C++;C Description As every one known, a footbal ...
- GridView点击排序
快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠 ...
- Codeforces Round #199 (Div. 2) A Xenia and Divisors
注意题目的数字最大是7 而能整除的只有 1,2,3,4,6,故构成的组合只能是1,2,4 或1,2,6或1,3,6,故分别统计1,2,3,4,6的个数,然后再分配 #include <iostr ...
- SpringMVC_The resource identified by this request is only capable of generating responses with characteristics
今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only capabl ...
- meta标签的用法
meta是用来在HTML文档中模拟HTTP协议的响应头报文.meta 标签用于网页的<head>与</head>中,meta 标签的用处很多.meta 的属性有两种:name和 ...
- ASCII Table - ASCII码对照表
ASCII控制字符 二进制 十进制 十六进制 缩写 可以显示的表示法 名称/意义 0000 0000 0 00 NUL ␀ 空字符(Null) 0000 0001 1 01 SOH ␁ 标题开始 00 ...
- php 上传图片
学习地址:http://www.imooc.com/video/2473 <?php header("content-type:text/html;charset=utf-8" ...
- Leetcode | N-Queens I & II
N-Queens I The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 2094 产生冠军(半拓扑排序+map)
产生冠军 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...