WPF MVVM从外部程序集

时间:2016-02-08 15:50:49

标签: c# wpf mvvm mef caliburn.micro

所以我继承了使用Caliburn.Micro的WPF应用程序的开发。我的任务是扩展应用程序并包含一些AddIn功能,我编写了AddIn功能的核心逻辑,这一切都运行得很好,直到我运行应用程序并且shell视图通知我它“无法找到TestViewModel的视图”< / p>

这是我在引导程序中的配置方法

protected override void Configure()
{
    this._log.Debug("-->AppBootstrapper.Configure[ENTER]");
    try
    {
        SplashScreenForm.SplashScreen.Dispatcher.BeginInvoke(
                (Action)(() => SplashScreenForm.SplashScreen.Message = "Initializing Container..."));

        this._container = new CompositionContainer(new AggregateCatalog(new DirectoryCatalog(".", "*")));
        var batch = new CompositionBatch();

        SplashScreenForm.SplashScreen.Dispatcher.BeginInvoke(
                (Action)(() => SplashScreenForm.SplashScreen.Message = "Initializing Dependencies..."));
        batch.AddExportedValue<IWindowManager>(new WindowManager());
        batch.AddExportedValue<IEventAggregator>(new EventAggregator());

        batch.AddExportedValue(this._container);
        this._container.Compose(batch);
    }
    catch (Exception ex)
    {
        this._log.ErrorFormat("-->AppBootstrapper.Configure - {0}\n{1}", ex.Message, ex);
        throw new Exception(ex.Message, ex);
    }

    this._log.Debug("-->AppBootstrapper.Configure[EXIT]");
}

然后我有两个程序集,AppMain包含主应用程序逻辑(这有一个ViewModels和Views文件夹,这些都加载正常),我还有一个AppAddinTest程序集,其中包含一个测试插件,这也包含一个ViewModels和Views文件夹中。

我的TestViewModel代码是:

[Export(typeof(TestViewModel))]
public class TestViewModel : BaseViewModel, ITestViewModel
{
    private readonly IEventAggregator _eventAggregator;

    private readonly IWindowManager _windowManager;

    [ImportingConstructor]
    public TestViewModel(IEventAggregator eventAggregator, IWindowManager windowManager)
    {
        this._eventAggregator = eventAggregator;
        this._windowManager = windowManager;
    }
}

TestView.xaml是:

<UserControl x:Class="Cleo.Windows.Ui.Views.TestView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Text="This is a test view from a different assembly!!"></TextBlock>
    </Grid>
</UserControl>

有没有人能够解释我做错了什么,以及为什么应用程序无法找到视图?

1 个答案:

答案 0 :(得分:0)

我敢打赌你没有在ViewModel所在的bootstrapping阶段添加程序集。 覆盖引导程序中的var blob = Utilities.newBlob(decoded, MimeType.JPEG, "nameOfImage"); currentFolder.createFile(blob);

SelectAssemblies()