网站空间在哪买好,活动推广方案怎么写,网址转换成二维码,山东青岛网站设计--概述这个项目演示了如何在WPF中使用各种Prism功能的示例。如果您刚刚开始使用Prism#xff0c;建议您从第一个示例开始#xff0c;按顺序从列表中开始。每个示例都基于前一个示例的概念。此项目平台框架#xff1a;.NET Core 3.1Prism版本#xff1a;8.0.0.1909提示… --概述这个项目演示了如何在WPF中使用各种Prism功能的示例。如果您刚刚开始使用Prism建议您从第一个示例开始按顺序从列表中开始。每个示例都基于前一个示例的概念。此项目平台框架.NET Core 3.1Prism版本8.0.0.1909提示这些项目都在同一解决方法下需要依次打开运行可以选中项目-》右键-》设置启动项目然后运行目录介绍Topic描述Bootstrapper and the Shell创建一个基本的引导程序和shellRegions创建一个区域Custom Region Adapter为StackPanel创建自定义区域适配器View Discovery使用视图发现自动注入视图View Injection使用视图注入手动添加和删除视图View Activation/Deactivation手动激活和停用视图Modules with App.config使用应用加载模块。配置文件Modules with Code使用代码加载模块Modules with Directory从目录加载模块Modules loaded manually使用IModuleManager手动加载模块ViewModelLocator使用ViewModelLocatorViewModelLocator - Change Convention更改ViewModelLocator命名约定ViewModelLocator - Custom Registrations为特定视图手动注册ViewModelsDelegateCommand使用DelegateCommand和DelegateCommandTCompositeCommands了解如何使用CompositeCommands作为单个命令调用多个命令IActiveAware Commands使您的命令IActiveAware仅调用激活的命令Event Aggregator使用IEventAggregatorEvent Aggregator - Filter Events订阅事件时筛选事件RegionContext使用RegionContext将数据传递到嵌套区域Region Navigation请参见如何实现基本区域导航Navigation Callback导航完成后获取通知Navigation Participation通过INavigationAware了解视图和视图模型导航参与Navigate to existing Views导航期间控制视图实例Passing Parameters将参数从视图/视图模型传递到另一个视图/视图模型Confirm/cancel Navigation使用IConfirmNavigationReqest界面确认或取消导航Controlling View lifetime使用IRegionMemberLifetime自动从内存中删除视图Navigation Journal了解如何使用导航日志部分项目演示和介绍① BootstrapperShell启动界面这个主要演示Prism框架搭建的用法step1在nuget上引用Prsim.Unitystep2修改App.xaml设置引导程序Application x:ClassBootstrapperShell.Appxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:localclr-namespace:BootstrapperShellApplication.Resources/Application.Resources
/Applicationpublic partial class App : Application{protected override void OnStartup(StartupEventArgs e){base.OnStartup(e);var bootstrapper new Bootstrapper();bootstrapper.Run();}}step3在引导程序中设置启动项目using Unity;
using Prism.Unity;
using BootstrapperShell.Views;
using System.Windows;
using Prism.Ioc;namespace BootstrapperShell
{class Bootstrapper : PrismBootstrapper{protected override DependencyObject CreateShell(){return Container.ResolveMainWindow();}protected override void RegisterTypes(IContainerRegistry containerRegistry){}}
}step4在MainWindow.xaml中显示个字符串Window x:ClassBootstrapperShell.Views.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlTitleShell Height350 Width525GridContentControl ContentHello from Prism //Grid
/Window②ViewInjection视图注册MainWindow.xaml通过ContentControl 关联视图Window x:ClassViewInjection.Views.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:prismhttp://prismlibrary.com/TitleShell Height350 Width525DockPanel LastChildFillTrueButton DockPanel.DockTop ClickButton_ClickAdd View/ButtonContentControl prism:RegionManager.RegionNameContentRegion //DockPanel
/WindowMainWindow.xaml.cs鼠标点击后通过IRegion 接口注册视图public partial class MainWindow : Window{IContainerExtension _container;IRegionManager _regionManager;public MainWindow(IContainerExtension container, IRegionManager regionManager){InitializeComponent();_container container;_regionManager regionManager;}private void Button_Click(object sender, RoutedEventArgs e){var view _container.ResolveViewA();IRegion region _regionManager.Regions[ContentRegion];region.Add(view);}}③ActivationDeactivation视图激活和注销MainWindow.xaml.cs这里在窗体构造函数中注入了一个容器扩展接口和一个regin管理器接口分别用来装载视图和注册regin窗体的激活和去激活分别通过regions的Activate和Deactivate方法实现public partial class MainWindow : Window{IContainerExtension _container;IRegionManager _regionManager;IRegion _region;ViewA _viewA;ViewB _viewB;public MainWindow(IContainerExtension container, IRegionManager regionManager){InitializeComponent();_container container;_regionManager regionManager;this.Loaded MainWindow_Loaded;}private void MainWindow_Loaded(object sender, RoutedEventArgs e){_viewA _container.ResolveViewA();_viewB _container.ResolveViewB();_region _regionManager.Regions[ContentRegion];_region.Add(_viewA);_region.Add(_viewB);}private void Button_Click(object sender, RoutedEventArgs e){//activate view a_region.Activate(_viewA);}private void Button_Click_1(object sender, RoutedEventArgs e){//deactivate view a_region.Deactivate(_viewA);}private void Button_Click_2(object sender, RoutedEventArgs e){//activate view b_region.Activate(_viewB);}private void Button_Click_3(object sender, RoutedEventArgs e){//deactivate view b_region.Deactivate(_viewB);}}④UsingEventAggregator事件发布订阅事件类定义public class MessageSentEvent : PubSubEventstring{}注册两个组件ModuleA和ModuleBprotected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog){moduleCatalog.AddModuleModuleA.ModuleAModule();moduleCatalog.AddModuleModuleB.ModuleBModule();}ModuleAModule 中注册视图MessageViewpublic class ModuleAModule : IModule{public void OnInitialized(IContainerProvider containerProvider){var regionManager containerProvider.ResolveIRegionManager();regionManager.RegisterViewWithRegion(LeftRegion, typeof(MessageView));}public void RegisterTypes(IContainerRegistry containerRegistry){}}MessageView.xaml视图中给button俺妞妞绑定命令UserControl x:ClassModuleA.Views.MessageViewxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:prismhttp://prismlibrary.com/ prism:ViewModelLocator.AutoWireViewModelTrue Padding25StackPanelTextBox Text{Binding Message} Margin5/Button Command{Binding SendMessageCommand} ContentSend Message Margin5//StackPanel
/UserControlMessageViewModel.cs在vm中把界面绑定的命令委托给SendMessage然后在方法SendMessage中发布消息using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using UsingEventAggregator.Core;namespace ModuleA.ViewModels
{public class MessageViewModel : BindableBase{IEventAggregator _ea;private string _message Message to Send;public string Message{get { return _message; }set { SetProperty(ref _message, value); }}public DelegateCommand SendMessageCommand { get; private set; }public MessageViewModel(IEventAggregator ea){_ea ea;SendMessageCommand new DelegateCommand(SendMessage);}private void SendMessage(){_ea.GetEventMessageSentEvent().Publish(Message);}}
}在MessageListViewModel 中接收并显示接收到的消息public class MessageListViewModel : BindableBase{IEventAggregator _ea;private ObservableCollectionstring _messages;public ObservableCollectionstring Messages{get { return _messages; }set { SetProperty(ref _messages, value); }}public MessageListViewModel(IEventAggregator ea){_ea ea;Messages new ObservableCollectionstring();_ea.GetEventMessageSentEvent().Subscribe(MessageReceived);}private void MessageReceived(string message){Messages.Add(message);}}以上就是这个开源项目比较经典的几个入门实例其它就不展开讲解了有兴趣的可以下载源码自己阅读学习。源码下载github访问速度较慢所以我下载了一份放到的百度网盘百度网盘链接https://pan.baidu.com/s/10Gyks2w-R4B_3z9Jj5mRcA 提取码0000---------------------------------------------------------------------开源项目链接https://github.com/PrismLibrary/Prism-Samples-Wpf技术群添加小编微信并备注进群小编微信mm1552923 公众号dotNet编程大全