Background

I am planning to create a small mobile client for dianping.com, which is a popular resturant rating service in China. I found the new HubTile control is so cool to wow my user, so just had a quick study. When trying to add it to my project, I found it is not supported by default in Caliburn.Micro.

Convention, Convention, It is magic

Caliburn has really strong and flexible convention system, so if you get anything new that Caliburn.Micro cannot recognize, you just need to do the following

static void AddCustomConventions()
    {			
        ConventionManager.AddElementConvention<HubTile>(HubTile.DataContextProperty, "DataContext", "Tap");
    }

So you may ask, what does it mean? There are 3 parameters in the above example
  • the first one is the property which caliburn can bind the data to
  • the second is the parameter you want to pass to the action
  • the third one is the event to invoke the action

So does it work now?

Let us try it out, first create a HubTile control in your page as follows

<toolkit:HubTile x:Name="NaviToDetail" Grid.Row="1" Grid.Column="0" 
                                         Margin="12,12,0,0"
                                         Source="/Images/breakfast.png"
                                         Title="Dessert"
                                         Notification="2 New&#x0d;&#x0a;Receipes"
                                         DisplayNotification="True"
                                         GroupTag="dianping" />

And then create an action in your ViewModel

        public void NaviToDetail()
        {
            MessageBox.Show("Susccess!"); // just to make sure the action will be called
        }

Run you program, and you will see a message box popping up when you tap the tile.

Last edited Sep 13, 2011 at 7:34 AM by wpcfan, version 1

Comments

No comments yet.