gpt4 book ai didi

silverlight-4.0 - MEF MVVM Silverlight 4中的导入问题

转载 作者:行者123 更新时间:2023-12-03 10:40:16 25 4
gpt4 key购买 nike

我正在使用MEF,MVVM和Silverlight4,以下是我的代码

Main.cs:

using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Diagnostics;
using System.ServiceModel.DomainServices.Client.ApplicationServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
public partial class Main : UserControl
{
public Main()
{
InitializeComponent();
// Satisfy the MEF imports for the class.
if (!DesignerProperties.IsInDesignTool)
{
CompositionInitializer.SatisfyImports(this);
}

}


/// <summary>
/// Sets the datacontext to the viewmodel for this view
/// </summary>
[Import(ViewModelTypes.MainViewModel)]
public object ViewModel
{
set
{
this.DataContext = value;
}
}
}

View 模型:
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows.Input;
[Export(ViewModelTypes.MainViewModel)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class MainViewModel : ViewModelBase
{
[ImportingConstructor]
public MainViewModel(IAuthenticationModel authModel, IprospectManagementModel managementModel)
{
this.authenticationModel = authModel;
this.managementModel = managementModel;
}

/// <summary>
/// The authentication model.
/// </summary>
private IAuthenticationModel authenticationModel;

/// <summary>
/// The Iprospect management model.
/// </summary>
private IprospectManagementModel managementModel;

}

以下是我遇到的错误,请尽我所能追查。

组成保持不变。更改由于以下错误而被拒绝:合成产生单个合成错误。根本原因在下面提供。查看CompositionException.Errors属性以获取更多详细信息。

1)找不到与约束'(exportDefinition.ContractName ==“MainViewModel”)'匹配的有效导出,无效的导出可能已被拒绝。

导致:
Cannot set import 'IProspectCommonApp.Client.Main.ViewModel (ContractName="MainViewModel")' on part 'IProspectCommonApp.Client.Main'.
Element: IProspectCommonApp.Client.Main.ViewModel (ContractName="MainViewModel") --> IProspectCommonApp.Client.Main

最佳答案

可能由于未导出IAuthenticationModel和/或IprospectManagementModel而失败。 MainViewModel通过ImportingConstructor导入了这些,因此如果尚未导出它们,则无法创建它们。

有关MEF调试的更多信息,请参见How to Debug and Diagnose MEF Failures

关于silverlight-4.0 - MEF MVVM Silverlight 4中的导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6426024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com