Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf MEF导入不适用于具有多个活动屏幕的Shell_Wpf_Shell_Screen_Mef_Caliburn.micro - Fatal编程技术网

Wpf MEF导入不适用于具有多个活动屏幕的Shell

Wpf MEF导入不适用于具有多个活动屏幕的Shell,wpf,shell,screen,mef,caliburn.micro,Wpf,Shell,Screen,Mef,Caliburn.micro,高I用户WPF/Calibur Micro/MEF。我尝试在shell中使用更活跃的屏幕。首先我定义屏幕-用户控件 屏幕视图模型 2.屏幕-视图模型 在第二个屏幕上,如果用户单击显示消息框的按钮,我只有一个按钮 没有最重要的部分外壳。外壳是WPF窗口 视图: 问题出在哪里 这里?导体。收集。激活 在您的ShellViewModel类型上,ProjectInfo和Project属性的类型应为iProjectInfo视图模型和IProjectsViewModel,因为这些是您导出的类型,您应该使用这

高I用户WPF/Calibur Micro/MEF。我尝试在shell中使用更活跃的屏幕。首先我定义屏幕-用户控件

  • 屏幕视图模型
  • 2.屏幕-视图模型

    在第二个屏幕上,如果用户单击显示消息框的按钮,我只有一个按钮

    没有最重要的部分外壳。外壳是WPF窗口

    视图:

    问题出在哪里

    这里?导体。收集。激活


    在您的
    ShellViewModel
    类型上,
    ProjectInfo
    Project
    属性的类型应为
    iProjectInfo视图模型
    IProjectsViewModel
    ,因为这些是您导出的类型,您应该使用这些接口。

    非常感谢,愚蠢的问题…我将视图模型类导出为接口…你是对的
    public interface IProjectsViewModel
    {
    
    }
    [Export(typeof(IProjectsViewModel))]
    public class ProjectsViewModel:Screen,
        IProjectsViewModel
    {
    
    }
    
    public interface IProjectInfoViewModel
    {
    
    }
    
    [Export(typeof(IProjectInfoViewModel))]
    public class ProjectInfoViewModel :Screen, 
        IProjectInfoViewModel
    {
        [Import]
        internal IMessageBox MsgBox { get; set; }
    
        public void BtnClick()
        {
            MsgBox.ShowInfo("Btn click",string.Empty);
        }
    }
    
    <Window x:Class="CaliburnSkelet.Views.ShellView"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            xmlns:Views="clr-namespace:CaliburnSkelet.Views" 
            xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" 
            Title="ShellView" Height="300" Width="300">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <!--<ContentControl x:Name="Projects" Grid.Column="0"/>
            <ContentControl x:Name="ProjectInfo" Grid.Column="1"/>-->
            <Views:ProjectsView  cal:View.Model="{Binding Projects}" 
                                 Grid.Column="0"/>
            <Views:ProjectInfoView cal:View.Model="{Binding ProjectInfo}"
                                   Grid.Column="1"/>
        </Grid>
    </Window>
    
    public interface IShellViewModel :IScreen
    {
        ProjectInfoViewModel ProjectInfo { get; set; }
        ProjectsViewModel Project { get; set; }
    }
    
    [Export(typeof(IShellViewModel))]
    public class ShellViewModel:Conductor<IScreen>.Collection.AllActive,
        IShellViewModel, IPartImportsSatisfiedNotification
    
    {
        [Import]
        public ProjectInfoViewModel ProjectInfo { get; set; }
    
        [Import]
        public ProjectsViewModel Project { get; set; }
    
        public void OnImportsSatisfied()
        {
        }
    }
    
      at CaliburnSkelet.BootStraper.MefBootStrapper.GetInstance(Type serviceType, String key) in E:\C# PROJECTS\CaliburnSkelet\CaliburnSkelet\BootStraper\MefBootStrapper.cs:line 69
       at Caliburn.Micro.Bootstrapper.DisplayRootViewFor(Type viewModelType)
       at Caliburn.Micro.Bootstrapper`1.OnStartup(Object sender, StartupEventArgs e)
       at System.Windows.Application.OnStartup(StartupEventArgs e)
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
    
    [Export(typeof(IShellViewModel))]
    public class ShellViewModel:Conductor<IScreen>.Collection.AllActive,
        IShellViewModel, IPartImportsSatisfiedNotification
    
    {
        //[Import]
        public ProjectInfoViewModel ProjectInfo { get; set; }
    
        //[Import]
        public ProjectsViewModel Project { get; set; }
    
        public void OnImportsSatisfied()
        {
            ProjectInfo=new ProjectInfoViewModel();
            Project=new ProjectsViewModel();
        }
    }
    
            [Import]
            internal IMessageBox MsgBox { get; set; }
    
            public void BtnClick()
            {
    //MsgBox is null
                MsgBox.ShowInfo("Btn click",string.Empty);
            }