Tag: prism

如何在MEF容器中交换/替换共享(单例)对象?

这可能很简单,但由于我是MEF领域的新手,这就是为什么我难以找到问题的解决方案。 我正在使用WPF + Prism和MEF作为DI容器的应用程序。 我想将我的对象(即RuleFile )与每个应用程序实例RuleFile ,方法是将它与文件说法RuleFile1.ruleapp相关联。 因此,我使用属性[PartCreationPolicy(CreationPolicy.Shared)]进行了[PartCreationPolicy(CreationPolicy.Shared)] ,将其视为单例,以便它在整个应用程序中与每个应用程序实例保持相同。 [Serializable()] [Export] [PartCreationPolicy(CreationPolicy.Shared)] public class RuleFile : NotifyPropertyChanged, IRuleFile { } 接下来,在ViewModel [ImportingContructor] ,如下所示,该对象与所需的相同。 [ImportingConstructor] public RuleViewModel(RuleFile ruleFile) [ImportingConstructor] public SchemaViewModel(RuleFile ruleFile) 到现在为止一切顺利。 使用下面的代码,我试图得到传递给视图模型的相同导出对象,如上所述,但container.GetExportedValue()给出一个不同的新对象引用: var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()); var container = new CompositionContainer(catalog); var exportObj = container.GetExportedValue(); 问题1:为什么我得到一个不同的引用虽然对象应该与CreationPolicy.Shared的单例对象相同? 问题2:最终,所有的努力都是用MEF DI容器中的反序列化对象来交换/替换RuleFile导出的对象?

棱镜模块加​​载锁定调度程序线程。 有没有解决的办法?

Prism应用程序我执行多个启动任务可能需要一段时间,如果其中一些任务无法正确执行,它将使应用程序在function上无法使用。 因此,我有一个在Shell之前显示的启动屏幕,并显示每个启动任务的状态日志。 (启动任务由模块中的共享服务处理。)屏幕包含一个将IsIndeterminate设置为True的ProgressBar(至少在启动任务运行时)。 我还在启动任务中包含了在显示日志中显示模块本身的初始化。 (日志中的第一项任务。) 我遇到的问题是我的一个模块加载了一个相当大的第三方库。 我最初有这个模块只是记录它的所有类型并将实际分辨率留给Unity。 但是,这提出了两个问题:1)当用户到达加载此模块中的视图的点时,应用程序将在加载此大型库时暂停。 2)在用户与视图交互之前,此模块中的某些业务逻辑应处于活动状态。 所以在我的IModule实现中,而不是为我的大多数服务调用RegisterType(),我正在调用RegisterInstance。 这一切都很好。 问题是,现在当Unity在这个模块中创建所有服务时,这个第三方库正在预先加载,我的模块初始化需要一段时间才能完成。 我的启动屏幕中的进度条没有动画,因为Dispatcher线程似乎被占用加载模块。 我可以做些什么来让这个缓慢加载模块异步加载或类似,以便进度条动画? 如果不可能的话,这不是世界的尽头,但拥有它会很好。

从不同的ViewModel执行相同的Prism命令

是否可以使用Prism从WPF应用程序中的不同ViewModel以某种方式执行一个命令? 让我解释一下我的意思。 我有MainMenuViewModel类: public class MainMenuViewModel { private ICommand _aboutCommand; public ICommand AboutCommand { get { if (_aboutCommand == null) { _aboutCommand = new DelegateCommand(() => { MessageBox.Show(“About menu item clicked!”); }); } return _aboutCommand; } } } 还有这个型号的视图: 应用程序中还有另一个模块,它应该以相同的行为执行命令(甚至可能更好 – 相同的命令): public class MunisatorViewModel { private ICommand _aboutCommandInAnotherModule; public ICommand AboutCommandInAnotherModule { get { […]

EventAggregator和ServiceLocator问题

我开始使用Prism和MVVM开发一个WPF项目,我正在尝试使用eventAggregator但是,当执行下面的行时会引发exception: IServiceLocator ob = ServiceLocator.Current; // This line causes a Null pointer exception EventAggregator = ob.GetInstance(); 但是我无法理解我做错了什么,也许这是一件非常简单的事情,但我已经在努力了几个小时。 希望有人可以帮助我,提前谢谢

参数可以传递给WPF用户控件吗?

可以将值或参数传递给WPF用户控件吗? 我正在使用MVVM模式。 哪里 ForeColor是托管SampleUserControl View的窗口的Viewmodel中的Type Color或Brush的属性。 顺便说一下,属性应该是Color还是Brush?

如何在WPF中重新编译空的DirectoryCatalog for MEF

我有这个步骤的应用程序: 启动应用程序和ConfigureAggregateCatalog 登录用户到应用程序 将DLL MEF模块下载到名为“Modules”的目录 刷新目录目录 – 有一个问题 我有空目录’模块’后下载DLL我试图加载模块但没有成功。 我在线上有一个错误,我称之为DirectoryCatalog.Refresh() 用户代码未处理System.ComponentModel.Composition.ChangeRejectedException消息=组合保持不变。 由于以下错误,更改被拒绝:组合产生多个组合错误,有14个根本原因。 根本原因如下。 查看CompositionException.Errors属性以获取更多详细信息。 1)由不可重组的导入阻止的导出变化’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor(Parameter =“downloadedPartCatalogs”,ContractName =“Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection”)’部分’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer’。 2)部分’Microsoft.Practices上的非重组导入’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader(ContractName =“Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)’阻止了导出的变化。 Prism.MefExtensions.Modularity.MefModuleManager”。 3)由不可重组的导入’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor(Parameter =“moduleInitializer”,ContractName =“Microsoft.Practices.Prism.Modularity.IModuleInitializer”)’阻止出口的变化’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager’。 4)部分’Microsoft.Practices’中不可重组的导入’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader(ContractName =“Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)’阻止了导出的变化。 Prism.MefExtensions.Modularity.MefModuleManager”。 5)由不可重组的导入’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor(Parameter =“moduleInitializer”,ContractName =“Microsoft.Practices.Prism.Modularity.IModuleInitializer”)’阻止出口的变化’Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager’。 6)部分’GXBilling.ViewsModels.ShellViewModel’上的不可重组导入’GXBilling.ViewsModels.ShellViewModel.ModuleManager(ContractName =“Microsoft.Practices.Prism.Modularity.IModuleManager”)’阻止了导出的变化。 7)发现多个导出匹配约束’((exportDefinition.ContractName ==“Microsoft.Practices.Prism.Regions.RegionAdapterMappings”)AndAlso(exportDefinition.Metadata.ContainsKey(“ExportTypeIdentity”)AndAlso“Microsoft.Practices。 Prism.Regions.RegionAdapterMappings” .Equals(exportDefinition.Metadata.get_Item( “ExportTypeIdentity”))))”。 导致:无法设置导入’Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor(Parameter =“regionAdapterMappings”,ContractName =“Microsoft.Practices.Prism.Regions.RegionAdapterMappings”)”’部分’微软。 Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior”。 元素:Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor(Parameter =“regionAdapterMappings”,ContractName =“Microsoft.Practices.Prism.Regions.RegionAdapterMappings”) – > Microsoft.Practices.Prism.MefExtensions。 Regions.Behaviors.MefDelayedRegionCreationBehavior – > AssemblyCatalog(Assembly =“Microsoft.Practices.Prism.MefExtensions,Version = 4.0.0.0,Culture = neutral,PublicKeyToken […]

MEF:来自Type的GetExportedValue?

使用MEF我可以创建并加载这样的类型: var view = Container.GetExportedValue(); 现在我想要做的是: Type t = typeof(MyView); var view = Container.GetExportedValue(); (当然,类型可能包含与MyView不同的内容)。 使用genericsGetExportedValue 是不可能的 – 有没有其他方法来实现这一点?

Prism 5 DelegateCommandBase.RaiseCanExecuteChanged抛出InvalidOperationException

我刚刚从Prism 4.1到5进行了更新,过去工作正常的代码现在会抛出InvalidOperationExceptions。 我怀疑根本原因是更新的异步DelegateCommands没有正确地编组到UI线程。 我需要能够从任何线程调用command.RaiseCanExecuteChanged()并为此在UI线程上引发CanExecuteChanged事件。 Prism文档说这就是RaiseCanExecuteChanged()方法应该做的事情。 然而,随着Prism 5的更新,它不再有效。 CanExecuteChanged事件在非UI线程上调用,我获得下游InvalidOperationExceptions,因为在这个非UI线程上访问UI元素。 这是提供解决方案提示的Prism文档: DelegateCommand包括对异步处理程序的支持,并已移至Prism.Mvvm可移植类库。 DelegateCommand和CompositeCommand都使用WeakEventHandlerManager来引发CanExecuteChanged事件。 必须首先在UI线程上构造WeakEventHandlerManager,以正确获取对UI线程的SynchronizationContext的引用。 但是,WeakEventHandlerManager是静态的,所以我无法构造它… 根据Prism文档,有谁知道如何在UI线程上构建WeakEventHandlerManager? 这是一个失败的unit testing,可以重现问题: [TestMethod] public async Task Fails() { bool canExecute = false; var command = new DelegateCommand(() => Console.WriteLine(@”Execute”), () => { Console.WriteLine(@”CanExecute”); return canExecute; }); var button = new Button(); button.Command = command; Assert.IsFalse(button.IsEnabled); canExecute = true; // Calling RaiseCanExecuteChanged […]

如何使用视图切换导航在Prism 6 WPF应用程序中注册模块?

我开始在MSVS 2015 Professional(russified)中开发Prism 6 WPF视图切换应用程序。 下面是我的解决方案表示(我在我的MSVS中请原谅俄语): 下面是我的应用程序的Bootstrepper: class Bootstrapper : UnityBootstrapper { protected override DependencyObject CreateShell() { return Container.Resolve(); } protected override void InitializeShell() { Application.Current.MainWindow.Show(); } } 我的两个模块都必须加载应用程序,并且每个模块都有Model in Models文件夹,View in Views文件夹和ViewModel文件夹中的ViewModel。 (根据技术指配,我的应用程序必须具有多达20-22个这样的模块。)应用程序用户将通过MainWindow的MainNavigationRegion中的radiobuttons切换这些视图。 下面是MainWindow XAML(没有radiobuttons): 我是Prism的初学者,我的问题是:如何在Bootstrepper类中注册我的两个模块(AuthorizationModule和CalibrationModule)? 我应该创建自己的实现IModuleCatalog的类吗? 例如AggregateModuleCatalog:IModuleCatalog {…}并在Bootstrepper中输入以下代码: protected override IModuleCatalog CreateModuleCatalog() { return new AggregateModuleCatalog(); } 或者使用Prism.Modularity.ConfigurationModuleCatalog并在Bootstrepper中输入以下代码: protected override IModuleCatalog CreateModuleCatalog() { […]

使用PRISM 4显示modal dialog

我正在使用PRISM和MVVM以及WPF开发.NET 4.0应用程序。 我目前有一个细分在区域中的shell,其中插入了视图。 当用户点击其中一个视图中的按钮时,我希望定制的模式对话框显示在所有视图的顶部,但仍在同一个shell中。 我查看了StockTrader RI示例及其RegionPopupBehavior的实现。 基本上,他们创建了一个依赖属性,允许他们定义具有特定的自定义行为的区域。 行为是负责处理相关视图渲染的行为,因此将其显示为弹出窗口。 这种方法的唯一缺点是所有其他视图仍处于活动状态,因此弹出窗口不是模态的。 我想这可以通过手动禁用shell中所有不需要的区域来解决,但我不确定这是多么“干净”。 我想知道是否有更好更简单的方法在Prism中显示模态弹出视图?