【问题标题】:Prism 4 Splash Screen with MEF bootstrapper带有 MEF 引导程序的 Prism 4 启动画面
【发布时间】:2011-09-18 18:31:53
【问题描述】:

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

我想我需要在模块管理器中订阅 LoadModuleCompleted 事件。我不能这样做,因为当我使用 MEF 引导程序中的容器解析模块管理器时,PRISM 框架调用 OnImportsSatisfied 来加载所有模块。 (太晚了,我想听这个)。

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

非常感谢!

【问题讨论】:

  • 您可以查看this project。它使用 Unity 引导程序,但您可能会发现它很有用。

标签: screen prism mef splash-screen


【解决方案1】:

如果您控制导入到项目中的组合部分,您可以在每个部分上实现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));
    }
}

【讨论】:

    猜你喜欢
    • 2011-05-03
    • 2017-04-30
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 2011-08-23
    • 1970-01-01
    相关资源
    最近更新 更多