Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
C# 温莎城堡和卡利本·米尔科指挥时的奇怪行为_C#_Wpf_Castle Windsor_Caliburn.micro - Fatal编程技术网

C# 温莎城堡和卡利本·米尔科指挥时的奇怪行为

C# 温莎城堡和卡利本·米尔科指挥时的奇怪行为,c#,wpf,castle-windsor,caliburn.micro,C#,Wpf,Castle Windsor,Caliburn.micro,在结合Castle Windsor和Caliburn.Micro(最新版本)时,我有一种奇怪的行为。我有一个ShellViewModel,它是IWorkspace的导体。当我启动我的应用程序时,我有一个(第一个实现的IWorkspace)添加到ShellViewModel.Items集合中。默认情况下应该是这样吗?我的引导程序配置错误吗 AppBootstrapper.cs public class AppBootstrapper : BootstrapperBase { IWinds

在结合Castle Windsor和Caliburn.Micro(最新版本)时,我有一种奇怪的行为。我有一个
ShellViewModel
,它是
IWorkspace
的导体。当我启动我的应用程序时,我有一个(第一个实现的
IWorkspace
)添加到
ShellViewModel.Items
集合中。默认情况下应该是这样吗?我的引导程序配置错误吗

AppBootstrapper.cs

public class AppBootstrapper : BootstrapperBase
{
     IWindsorContainer container = new WindsorContainer();

    public AppBootstrapper()
    {
        container.Register(Component.For<IShell>().ImplementedBy<ShellViewModel>());

        container.Register(
            Classes.FromThisAssembly().BasedOn<IWorkspace>().WithServiceAllInterfaces().WithServiceSelf().LifestyleTransient()
            );


        container.Register(Component.For<IEventAggregator>().ImplementedBy<EventAggregator>());
        container.Register(Component.For<IWindowManager>().ImplementedBy<WindowManager>());
        Initialize();
    }

    protected override object GetInstance(Type service, string key)
    {
        return string.IsNullOrWhiteSpace(key) ? container.Resolve(service) : container.Resolve<object>(key);
    }

    protected override IEnumerable<object> GetAllInstances(Type service)
    {
        return new[] { container.ResolveAll(service) };
    }

    protected override void OnStartup(object sender, StartupEventArgs e)
    {
        DisplayRootViewFor<IShell>();
    }
}
接口:

public interface IShell: IConductor, IGuardClose
{

}
public interface IWorkspace
{

}

你有bootstrapper中的build()覆盖吗?作为一个附加组件,我想说它似乎配置正确,我个人不使用windor。有很多例子。有一点是,如果您计划使用Conductor,则在构建应用程序时,每个“工作区”都需要某种生命周期、屏幕或IScreen作为各个工作区的baseviewmodel的一部分。我不会重写build()方法。在这个简单的示例中,我忘记了向IWorkspace添加ISceen。但是,只要我在执行IWorkspace Castle或Caliburn解决该接口并将其添加到Items集合中,问题就仍然存在。这是自动完成的,而不是通过我的代码激活它们(…)这是我想要摆脱的行为。当然,我可以执行object而不是IWorkspace,
Conductor.Collection.OneActive
不会自动为Conductor填充Items集合。实际上你必须在某个地方做。HelloScreens示例表明它必须是隐式的。你在什么地方告诉它,把它推进收藏。所以这不是正常的行为。我建议您回顾一下Winsor和CM组合的现有示例。不幸的是,它们中的很多都是基于1.52构建的,可惜它的设计非常陈旧。因此,您可能需要将代码重构为2.01,这也是我所期望的,但是我在这里发布了整个项目(没有发布app.xaml),它复制了这种行为。正如您在ShellView.xaml中看到的,我正在打印当前计数。当应用程序启动时,它会打印1并将contentpresenter绑定添加到ActiveItem,它会呈现Workspace1View.xaml(这个xaml只是一个表示workspace 1的文本块),因此我看不到在这个小测试项目中我调用它的位置。
<Window x:Class="CastleCaliburnTest.Shell.ShellView"
         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" 
         xmlns:local="clr-namespace:CastleCaliburnTest.Shell"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300" Background="HotPink">
<Grid>
        <TextBlock Text="{Binding Items.Count}" FontSize="48"></TextBlock>
</Grid>
 public class Workspace1ViewModel : IWorkspace
{
    public Workspace1ViewModel()
    {
        Console.WriteLine("Workspace 1 created");
    }
}
public interface IShell: IConductor, IGuardClose
{

}
public interface IWorkspace
{

}