【发布时间】: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