- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
据我了解,Prism 不会保留对创建的模块实例的引用。
当我无法访问当前正在使用的模块对象的实例时,如何从一个模块访问另一个模块中的非静态方法?
编辑:我通过从 View 中检索数据上下文并将其转换为使用的模型(我想要的方法所在的位置)来使其工作。不确定这是否是好的做法。
IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
IRegion region = regionManager.Regions["RegionName"]; ;
Module.Views.View currentView= null;
foreach (Module.Views.View view in region.ActiveViews)
{
currentView = view;
}
var model = (Module.Model)currentView.DataContext;
mode.Method();
最佳答案
模块定义(也就是实现 IModule
的类)除了框架调用的 Initialize
方法外,不包含任何值得为任何人调用的方法。
如果你想在一个模块中实现一个方法并在另一个模块中使用它(或者在同一个模块中,也就是说,没关系),创建一个类并实现一个接口(interface)。
例子:
public interface IMyService
{
void MyMethod();
}
internal class MyImplementation : IMyService
{
#region IMyService
public void MyMethod()
{
// do something useful ModuleA's way
}
#endregion
}
internal class ModuleA : IModule
{
public ModuleA( IUnityContainer container )
{
_container = container;
}
#region IModule
public void Initialize()
{
_container.RegisterType<IMyService, MyImplementation>();
}
#endregion
#region private
private readonly IUnityContainer _container;
#endregion
}
internal class SomeClass
{
public SomeClass( IMyService myService )
{
_myService = myService;
}
public void SomeMethod()
{
// use ModuleA's method here:
_myService.MyMethod();
}
#region private
private readonly IMyService _myService;
#endregion
}
关于c# - WPF, Prism : How to access non-static method in other module?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45098192/
我想将使用 Prism 4 编写的项目迁移到 Prism 6。 在 Prism 4 中 CompositePresentationEvent类型位于Microsoft.Practices.Compos
Pattern of pub-sub events is that the publisher should not know or care if there are any subscribers
我刚刚使用 MVVMLight、PRISM 和 DryIoc 启动了我的第一个 WPF 应用程序。 App.xaml 引用 prism:PrismApplication,如 https://prism
Microsoft 的 Patterns and Practices 提供的示例非常有用: 大约六个更简单的快速入门 其中涉及具体问题 股票交易者引用实现 ,这是一个相当全面的应用程序 但它缺乏更有用
prism 中共享服务的目的和用途是什么? 哪些事情会让我认为我必须使用共享服务而不是 Event Aggregator? 最佳答案 从事件订阅者的角度来看 EventAggregator,它有利于获
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 3年前关闭。 Improve this qu
寻找一个简单的 helloWorld EventAggregator 示例。我试图理解这一点,并且在遵循 RI 示例时遇到了一些困难。 谢谢 N 最佳答案 Prism 4.0 包括 EventAggr
我只是想知道区域的意义是什么。我想我不明白他们解决的问题。 例如,我看到很多人使用区域作为导航区域,但是为什么不将 ItemsControl 绑定(bind)到 ObservableCollectio
最近想将我的 WPF Prism 应用程序迁移到 7.1,这样做时我遇到了有关 Unity.Abstractions 的丢失引用错误。 将 Prism nuget 软件包升级到 Prism7.1,如下
在我的根 View 模型中,我称之为 await _navigationService.NavigateAsync( "/NavigationPage/Page1of2", useMo
在 2.1.x 时间框架中讨论了与 Prism 的集成,我们是 @2.4.x,Prism 4 现已推出,/contrib 中的 RIStockTrader 示例只是一个默认的 XAML 项目。 它应该
我正在使用 Prism4,并且在我的一个模块中,我试图用一个区域注册一个 View ,并处理它的按钮单击事件(当用户单击 View 上的按钮时发布)。 public class MyModule :
几个月来,我一直在将 Prism 2.0 用于个人项目。我最近听说过 Caliburn,我想知道是否有令人信服的理由让我考虑这样做。 我喜欢 Prism 的动态模块加载能力。我打算为我的应用程序构建模
我正在尝试对我的 Windows 应用商店应用程序中的暂停事件使用react。我添加了适当的回调方法,但遇到了问题: App.Current.Suspending += Current_Suspend
我目前正在尝试完成 this tutorial让 Prism 与 Spring.net 一起工作。 通过 NuGet(或手动引用程序集)引用 Prism4 和 Spring.Net 后,设置 Boot
几个月来,我一直在使用带有以下 XAML 命名空间声明的 Prism 6: xmlns:prism="http://www.codeplex.com/prism" 但我注意到这个命名空间 URL(重定
我在 PRISM 中实现应用程序,它需要从 dll 文件中动态导入模块。我设法做到了 - 他们正在导入,但我无法显示它。我决定创建一个特殊的模块来封装它——让我们称之为 ModuleDock。所以我们
我要创建的是一个 Silverlight 应用程序,其中包含几个选项卡/模块,这些选项卡/模块都是单独的 DLL。 我看到 PRISM 具有似乎针对 UI 的 Shell/Module 概念,并且我找
请帮忙 - 我迷路了! 我正在编写一个具有一些控件和一些屏幕的小型桌面应用程序。这应该稍后与一个小型网站集成,也有一些屏幕。这个想法是让用户编辑视频并选择图像,然后与她的 friend 分享他们的结果
我在使用方法时遇到问题 this.regionManager.RegisterViewWithRegion("TextRegion", typeof(TextView)); 如果我以某种方法在 Boo
我是一名优秀的程序员,十分优秀!