【问题标题】:caliburn micro tutorial problemcaliburn微教程问题
【发布时间】:2011-02-03 03:20:27
【问题描述】:

我刚刚开始 CM 教程,直到最后一个示例 here。我想更好地了解我可以用 CM 做什么,所以我做了一些我通常会在 wpf 项目中做的事情,为 Views 创建一个文件夹,为 ViewModels 创建一个文件夹。约定仍然应该找到一切,对吧?

所有其他示例都以这种方式工作得很好,但是由于对 CM 和如何调试 silverlight 一无所知,我无法解释似乎是数据上下文问题 - 除了显示添加按钮之外什么都没有。

有人能发现问题吗?

干杯,
浆果

虚拟机

[Export(typeof(IShell))]
public class ShellWithCompositionViewModel : PropertyChangedBase
{
    public BindableCollection<Model> Items { get; private set; }

    public ShellWithCompositionViewModel() {
        Items = new BindableCollection<Model>
                {
                    new Model {Id = Guid.NewGuid()},
                    new Model {Id = Guid.NewGuid()},
                    new Model {Id = Guid.NewGuid()},
                    new Model {Id = Guid.NewGuid()}
                };
    }

    public void Add() { Items.Add(new Model {Id = Guid.NewGuid()}); }

    public void Remove(Model child) { Items.Remove(child); }
}

查看

<UserControl x:Class="Caliburn.Micro.Hello.Views.ShellWithCompositionView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:cal="http://www.caliburnproject.org"
         >
<StackPanel>

    <ItemsControl x:Name="Items">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Button Content="Remove" cal:Message.Attach="Remove($dataContext)" />
                    <TextBlock Text="{Binding Id}" />
                </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

    <Button Content="Add" cal:Message.Attach="Add" />

</StackPanel>

开机

namespace Caliburn.Micro.Hello
{
    //public class HelloBootstrapper : Bootstrapper<ShellViewModel> { }
    //public class HelloBootstrapper : Bootstrapper<ShellWithParametersViewModel> { }
    public class HelloBootstrapper : Bootstrapper<ShellWithCompositionView> { }
}

修复

// left off the model the 1st time (caps not needed!)
public class HelloBootstrapper : Bootstrapper<ShellWithCompositionViewMODEL> { }

【问题讨论】:

  • 呃...这实际上是一个简单的问题,绝对不是 CM 问题。如果有人想要一些快速回答点,线索就在引导程序中。

标签: silverlight caliburn.micro caliburn


【解决方案1】:

问题在于您的引导程序引用了视图而不是视图模型。你应该把它改成这样:

public class HelloBootstrapper : Bootstrapper<IShell> { }

此外,除了应用导出属性之外,请确保在 ShellWithCompositionViewModel 上实现 IShell 接口。

【讨论】:

  • 是的 - 没想到我必须等待 you 获得十分 :--)
  • 等一下,是省略括号的标记还是您真的要在没有泛型类型的情况下阅读?应该是 HelloBootstrapper : Bootstrapper{{ShellWithCompositionView}} { } 根据已编辑的问题。干杯
猜你喜欢
  • 2013-05-01
  • 1970-01-01
  • 2013-09-10
  • 2011-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-16
相关资源
最近更新 更多