All About Actions Tutorial

Topics: Actions & Coroutines, Bugs, Getting Started
Jan 18, 2012 at 9:43 PM
Edited Jan 18, 2012 at 9:55 PM

Caliburn Micro is definetly fast to learn, provided one is familiar with MVVM concepts.

I had an issue with biding in one of the tutorials . I could not get the AllAbout Actions Tutorial to work completly , or only using conventions.

However as Soon as I include this line in the user control of the ShellIView.xaml

cal:Bind.Model="Shell"

The application generates an exception, stops running or does not respond to the buttons or both.

"Could not locate any instances of contract Shell"  from 

protected

override object GetInstance(Type serviceType, string key) of Bootstrapper.

 

 Furthermore the method protected override void DisplayRootView() will not compile because

Error 1 'CaliburnMicroApplication2.MefBootstrapper.DisplayRootView()': no suitable method found to override ...

using the Bootstrapper as per the tutorial..

I commented the DisplayRootView override methiod out and use both attributes above ShelllViewModel:

[

Export("Shell", typeof(IShell ))]  

[Export(typeof(IShell ))]  

 public class ShellViewModel : PropertyChangedBase, IShell ..

Perhaps somebody can explain, but I think it is possibly my lack of Mef knowledge..

Maybe this will help some others doing that tutorial. Posted it under the tutorial ..

Perhaps there is another way to get it right but I tried all permutations and this finally worked.

Coordinator
Jan 19, 2012 at 3:10 AM

I think you may be mixing the ViewModel-First and the View-First approaches. I'm not sure based on your explanation. Also, I think that the docs may have gotten slightly out of date with the latest release because DisplayRootView no longer exists. The equivalent action is to override OnStartup. Sorry about that.

Coordinator
Jan 19, 2012 at 3:13 AM

I've fixed up the docs.

Jan 20, 2012 at 11:36 AM

Hi I am afraid I am confusing something, perhaps somebody can help.

I also tried the bubble action sample and as soon as I put in the cal:Bind.Model = Shell into the Usercontrol of shellview.xaml the project crashes upon running it with the same exception. 

<

UserControl x:Class ="Caliburn.Micro.BubblingAction.ShellView"
 
 
 

 

xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation

 xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"

 

xmlns:cal ="http://www.caliburnproject.org" 

 

cal:Bind.Model ="Shell">

 

Putting both attributes on top of shellviewmodel, fixed it, but am not sure that is the right way:

 

[

Export(typeof(IShell))]

[

Export("Shell", typeof(IShell))]

 

 

 

public class ShellViewModel : IShell

 

Perhaps I am doing something else wrong. I can get it to work perfectly by just using the binding by convention.

Coordinator
Jan 20, 2012 at 1:53 PM

Why are you putting Bind.Model="Shell" ? Did you download the samples and try them out? I think you are mixing two different techniques.

Jan 20, 2012 at 4:11 PM
Edited Jan 20, 2012 at 4:14 PM

from http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=Documentation

after "Finally, we will alter our view to pull in the VM and perform all bindings:"

"<UserControl x:Class="Caliburn.Micro.ViewFirst.ShellView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:cal="http://www.caliburnproject.org"
             cal:Bind.Model="Shell">
    <StackPanel>
        <TextBox x:Name="Name" />
        <Button x:Name="SayHello"
                Content="Click Me" />
    </StackPanel>
</UserControl> "

"Notice the use of the Bind.Model attached property. This resolves our VM by key from the IoC container, sets the Action.Target and DataContext and applies all conventions."

 My understanding is that this is view first design.?