带 MEF 引导程序的 Prism 4 初始屏幕

发布于 2024-11-16 01:48:12 字数 281 浏览 2 评论 0原文

我有一个使用 MEF 引导程序的 prism 4 应用程序。我已经从引导程序实现了一个启动屏幕,并希望在模块管理器加载应用程序/模块时向用户提供模块信息(当它们加载时)。

我想我需要订阅模块管理器中的 LoadModuleCompleted 事件。我无法执行此操作,因为当我使用 MEF 引导程序中的容器解析模块管理器时,PRISM 框架会调用 OnImportsSatisfied 来加载所有模块。 (这已经太晚了,因为我想听这个)。

如何显示带有显示模块信息/进度的进度条的启动窗口?

非常感谢!

I have a prism 4 application using an MEF bootstrapper. I have implemented a splash screen from the bootstrapper and want to provide the user with module info (as they are loaded) while the module manager is loading the app/modules.

I think I need to subscribe to the LoadModuleCompleted event in the module manager. I cannot do this because when I resolve the module manager with the container in the MEF bootstrapper the PRISM framework calls OnImportsSatisfied which loads all the modules. (This is too late since I want to listen for this).

How can I display a splash window with a progress bar displaying module info/progress?

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2024-11-23 01:48:12

如果您控制导入到项目中的组成部分,则可以在每个部分上实现 IPartImportsSatisfiedNotification 并让它们向某些导入的进度监视器类报告自己的进度:

public interface IProgressMonitor
{
    void ReportComposed(Type type);
}

[Export(typeof(IProgressMonitor))]
public class ProgressMonitor : IProgressMonitor
{
    public ProgressMonitor()
    {
        var loadHeuristic = this.GetPreviousLoadProgress();
        if (loadHeuristic == null)
        {
            // Never been loaded before, so it's unclear how long it will take
            // Set indeterminate progress bar.
        }
        else
        {
            // Use previous load times to estimate progress.
            _loadHeuristic = loadHeuristic;
            _progress = 0;
        }
    }

    public void ReportComposed(Type type)
    {
        if (_loadHeuristic != null)
        {
            this.IncrementProgress();
        }
    }
}

[Export]
public class FooExport : IPartImportsSatisfiedNotification
{
    [Import]
    internal IProgressMonitor ProgressMonitor { get; set; }

    public void OnImportsSatisfied()
    {
        this.ProgressMonitor.ReportComposed(typeof(FooExport));
    }
}

If you control the composed parts that are imported into your project, you can implement IPartImportsSatisfiedNotification on each and have them report their own progress to some imported progress monitor class:

public interface IProgressMonitor
{
    void ReportComposed(Type type);
}

[Export(typeof(IProgressMonitor))]
public class ProgressMonitor : IProgressMonitor
{
    public ProgressMonitor()
    {
        var loadHeuristic = this.GetPreviousLoadProgress();
        if (loadHeuristic == null)
        {
            // Never been loaded before, so it's unclear how long it will take
            // Set indeterminate progress bar.
        }
        else
        {
            // Use previous load times to estimate progress.
            _loadHeuristic = loadHeuristic;
            _progress = 0;
        }
    }

    public void ReportComposed(Type type)
    {
        if (_loadHeuristic != null)
        {
            this.IncrementProgress();
        }
    }
}

[Export]
public class FooExport : IPartImportsSatisfiedNotification
{
    [Import]
    internal IProgressMonitor ProgressMonitor { get; set; }

    public void OnImportsSatisfied()
    {
        this.ProgressMonitor.ReportComposed(typeof(FooExport));
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文