Print Page | Close Window

Typo in "Add a MainPageViewModel"

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3472
Printed Date: 28-Mar-2024 at 7:58am


Topic: Typo in "Add a MainPageViewModel"
Posted By: dcuccia
Subject: Typo in "Add a MainPageViewModel"
Date Posted: 03-Jun-2012 at 1:39pm
In section "Add a MainPageViewModel" on the http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-bare-bones-mvvm#HWhybotherwiththefolders3F - bare bones MVVM page, #4 should show:

public void AskForIt()
{
    MessageBox.Show(
       string.Format(CultureInfo.CurrentCulture,
       "One {0}, coming right up!", DrinkName)); // don't do this in real app
}

not

public void AskForIt()
{
    MessageBox.Show(
       string.Format(CultureInfo.CurrentCulture,
       "One {0}, coming right up!", DrinkName.Text)); // don't do this in real app
}



Replies:
Posted By: dcuccia
Date Posted: 03-Jun-2012 at 4:08pm
One more:

In "Ask the Mixologist" section here:  http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-data-in-listbox - http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-data-in-listbox  

"On the other hand, the SelectedDrinkOrder property never changes. The private setter is called exactly once, in the constructor, before the View can bind to it. The property always delivers the same collection instance even though the contents of the collection change."

should instead be:

"On the other hand, the 
DrinkOrders property never changes. The private setter is called exactly once, in the constructor, before the View can bind to it. The property always delivers the same collection instance even though the contents of the collection change."


Posted By: dcuccia
Date Posted: 03-Jun-2012 at 4:16pm
on  http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-entity-views - http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-entity-views

1. Delete the <UserControl.Resource>

should be

1. Delete the 
<UserControl.Resources>


Posted By: dcuccia
Date Posted: 03-Jun-2012 at 5:22pm
Nitpicky, but if a user implements the optional explicit binding for the TextBox in section "Can I specify some data bindings explicitly?" at the bottom of this page:

http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-conventions-diagnostics - http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-conventions-diagnostics

Then in http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-talk-to-view - Talk to the View the following code won't work without adding the x:Name="DrinkName" back in:

       void IMainPage.ReadyForNewDrink()
        {
            DrinkName.Text = string.Empty;
            DrinkName.Focus();
        }

 Also in "Talk to the View", 

namespace HappyHour
{
   public partial class MainPage : IMainPage
    {

should instead be:

namespace HappyHour.Views
{
   public partial class MainPage : IMainPage
    {


Posted By: dcuccia
Date Posted: 03-Jun-2012 at 5:54pm
On http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-images-valueconverters - Images And ValueConverters :

7. Substitute Image for TextBox.

should be:

7. Substitute Image for TextBlock.


Posted By: dcuccia
Date Posted: 03-Jun-2012 at 9:25pm
Also in  http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-images-valueconverters - Images And ValueConverters  - no images are shown following the code in section "Show images in the DrinkOrderEntityView". 5 extra steps are necessary:

1) Add new "images" subfolder to the "assets" folder in the HappyHour project
2) Add all images in "src\Samples\HappyHour\Mixers\images" to the new folder
3) Edit: (I don't think #3 is actually necessary...added it before I discovered #5 below)
3) Add the PathToImageSourceConverter to App.xaml, which should now look like this:
<Application x:Class="HappyHour.App"
            ...
             xmlns:cocktail="clr-namespace:Cocktail;assembly=Cocktail.SL"
             ...>
    <Application.Resources>
        <!--  Resources scoped at the Application level should be defined here.  -->
        <ResourceDictionary>
            <local:AppBootstrapper x:Key="bootstrapper" />
            <cocktail:PathToImageSourceConverter x:Key="PathToImageSourceConverter" />
            ...

4) Delete old "happyhour_logo.png" in "assets" root folder and update image reference in MainPage.xaml to:

<Image Source="/HappyHour;component/assets/images/happyhour_logo.png" Grid.Column="1" />

5) Add a call to base.Configure(); in the first line of AppBootstrapper.Configure();


Also, below in "Customizing the custom convention" the Configure() method should be:

protected override void Configure()
{
// ...
   ConfigurePathToImageSourceConverter();
}

not

protected
override void Configure()
{
   // ...
   
ConfigureImageConverter();

}

...and the ConfigureImageConverter() method should be

private static void ConfigurePathToImageSourceConverter()
{
    PathToImageSourceConverter.DefaultPathFilter =
        path => string.IsNullOrEmpty(path) ?
           null : "/HappyHour;component/assets/images/" + path.Trim();

    PathToImageSourceConverter.DefaultMissingImage =
        PathToImageSourceConverter.GetImageFromPath("missing_drink.jpg");

}

not

private static void ConfigurePathToImageSourceConverter()
{
    PathToImageSourceConverter.PathFilter =
        path => string.IsNullOrEmpty(path) ?
           null : "/HappyHour;component/assets/images/" + path.Trim();

    PathToImageSourceConverter.MissingImage =
        PathToImageSourceConverter.GetImageFromPath("missing_drink.jpg");

}


Posted By: dcuccia
Date Posted: 03-Jun-2012 at 9:53pm
Just finished the walkthrough, and just wanted to say thanks very much for this tutorial and for Cocktail in general. It is so useful that I will definitely point my colleagues to it as the first reference "getting started" with XAML programming.

David Cuccia
Costa Mesa, CA
Lead developer, Virtual Photonics Technology Initiative (www.virtualphotonics.org)
CTO, Modulated Imaging, Inc. (www.modulatedimaging.com)


Posted By: johnl
Date Posted: 04-Jun-2012 at 11:22am
Thanks a ton David.

I'll work with Ward (the author of the Happy Hour Tutorial) and get these edits into the text asap.

I'll post here with an update as soon as we have had a chance to review and make the changes.


Posted By: WardBell
Date Posted: 04-Jun-2012 at 8:48pm
Hi David - Thanks for the kind words ... and for all the typos you caught!

I think I've transcribe them all to the updated tutorial documentation on the DRC. All, that is, except the fixes you prescribed for  http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-images-valueconverters - Images And ValueConverters .  I made the substitution of ConfigurePathToImageSourceConverter for ConfigureImageConverter. I fixed the implementation of the that static method (which needed an update even from your correction).

But I think the steps you mentioned as 1-4 are already covered at the http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-images-valueconverters#HAddHappyHourimagesasresources - top of the lesson . And #5 - calling base.Configure() - that was already there from a previous lesson in which we added a rule to C.M's ViewLocator.NameTransformer.

Please help me out if you think I missed something.

A+ and gold star to you for your help.

Cheers,

Ward


Posted By: dcuccia
Date Posted: 05-Jun-2012 at 4:24pm
Hi Ward - glad it was helpful. Gold stars are my favorite. :)

I totally missed the first steps (e.g. my "1-4") at the top of the lesson for "Images And ValueConverters" - thanks for pointing that out.

For #5 - below is what I see on the http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-entity-views - Entity Views page, so I guess "base.Configure()" should be added there?

Create our own naming convention

Cocktail can’t anticipate every convention we dream up. Fortunately, the naming conventions are ours to amend. Customizing the naming conventions is an advanced feature but it’s not hard. We’d dearly like to see this work and drive home the point that any class can be a ViewModel. So let’s tweak the conventions … as if we knew what we were doing.

1. Open the AppBootstrapper class file.

2. Override the base Configure method.

3. Add a NameTransformer rule.

C#
protected override void Configure()
{
    Caliburn.Micro.ViewLocator.NameTransformer
       // Map "Model" classes to views in "HappyHour.Views"
       .AddRule(@"^Model\.(\w*)(?<basename>)", "HappyHour.Views.${1}Entity${basename}View");
}



Posted By: WardBell
Date Posted: 05-Jun-2012 at 6:23pm
Hi David - yes, I should have shown the base.Configure override on that  http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-tutorial-entity-views - Entity Views  page in addition to talking about it in step #2.  Thanks again for giving such close attention to the tutorial. I hope your effort is rewarded with great success using Caliburn Micro, DevForce and Cocktail.



Print Page | Close Window