开发者

caliburn micro tutorial problem

I'm just starting the tutorial for CM and up to the last example here. I wanted to get a better feel for what I can do with CM, so I did some one thing I would normally do in a wpf project, make a folder for Views and a folder for ViewModels. Conventions should still find everything, right?

All of the other examples work great this way, but between being ignorant about both CM and how to debug silverlight, I'm at a loss to explain what appears to be a data context issue - nothing but the add button displays.

Can someone spot the problem?

Cheers,

Berryl

VM

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

    public ShellWithCompositionViewM开发者_Python百科odel() {
        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); }
}

VIEW

<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>

BOOT

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

The FIX

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


The problem is that your Bootstrapper references the View rather than the ViewModel. You should change it to this:

public class HelloBootstrapper : Bootstrapper<IShell> { }

Also, make sure that you implement the IShell interface on ShellWithCompositionViewModel in addition to applying the export attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜