Home » Blog

rounded header

Archive for the ‘General’ category

Caliburn Micro Part 1: Getting Started

tag icon Tagged as General, WPF

A few days ago I blogged about our new Dashboard sample included in WPF Elements. The sample demonstrates how to create a sales dashboard using a few of our WPF controls like the Data Grid, Time Explorer and Charts. It was built with the help of the Caliburn Micro framework to give it a robust MVVM architecture. In this blog post I’ll walk you through a simple tutorial for getting started with using Caliburn Micro in a WPF application. This is just part 1 in a series I will be writing so I hope you’ll subscribe and follow along with me as we build up to a useful application.

Step 1: Getting Started

Caliburn Micro targets .NET framework 4.0, so you’ll need Visual Studio 2010 to create the application. Start by creating a new WPF Application and add a reference to Caliburn.Micro.dll and System.Windows.Interactivity.dll which come with the Caliburn Micro download. Since Caliburn Micro is going to take care of creating the window for you, delete MainWindow.xaml and remove the StartupUri attribute from App.xaml. App.xaml will now look like this:

<Application x:Class="CaliburnMicroApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
 
  </Application.Resources>
</Application>

Step 2: The View Model

Caliburn Micro promotes a View-Model-First approach, so the next step is to add a class to represent the view model. Large applications can have many view models, each of which provides the logic for a different view. Below is a code example of an empty view model. Since this tutorial is focused on simply getting started with incorporating Caliburn Micro into a WPF application, we are not going to make the view model do anything for now.

using Caliburn.Micro;
 
namespace CaliburnMicroApp
{
  public class AppViewModel : PropertyChangedBase
  {
 
  }
}

The first thing to notice here is the name of the class. Caliburn Micro expects a particular naming convention so it can hook up the view model to the appropriate view. The class name of a view model should end with “ViewModel”. What you put in front of “ViewModel” is up to you. The other thing to notice here is that this class extends the PropertyChangedBase. This is provided by Caliburn Micro and makes it easy to raise property change notifications without needing to implement INotifyPropertyChanged in all your view models. Although this example view model doesn’t do anything, I’ve included the PropertyChangedBase as good practice. When adding properties to the view model, it will come in handy.

Step 3: The View

In order to display something in the window, you’ll need to create a view for the view model created in the previous step. This is as simple as adding a new UserControl to the project as seen below. I should point out again that Caliburn Micro expects a particular naming convention so it can hook up the view to the appropriate view model. View names should end with “View” and start with the same name you used for the view model. So for my example here, “AppView” is the view for rendering the “AppViewModel”. In the code below I have also set the width, height and background of the grid so that when you run this application you can see that it is working correctly.

<UserControl x:Class="CaliburnMicroApp.AppView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
  <Grid Width="300" Height="300" Background="LightBlue">
 
  </Grid>
</UserControl>

Step 4: The Bootstrapper

The bootstrapper is the mechanism used to incorporate Caliburn Micro into your application. It is also a place where you can configure the framework for the needs of your application. For the purposes of this tutorial, I have used a very simple bootstrapper implementation seen here:

using Caliburn.Micro;
 
namespace CaliburnMicroApp
{
  public class AppBootstrapper : Bootstrapper<AppViewModel>
  {
  }
}

Caliburn Micro has 2 different bootstrappers available. The one used above lets you set the generic type to be the view model that you want to be used at startup. The last step is to tell the application to use the bootstrapper. This is done by adding your bootstrapper to a resource dictionary in App.xaml. After doing this, App.xaml will now look something like this:

<Application x:Class="CaliburnMicroApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:local="clr-namespace:CaliburnMicroApp"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
          <local:AppBootstrapper x:Key="bootstrapper" />
        </ResourceDictionary>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>

And that’s it

Stay tuned for Part 2 to see something with a little more substance

Now when you run up the application, you’ll see a small window with a light blue background. Your application is now primed and ready to take advantage of all the great support provided by Caliburn Micro. It’s easy to get help for using this framework due to its growing community. You can also look through the documentation on CodePlex.

You can grab the full Visual Studio 2010 solution I made for this tutorial here.

In the next part of this blog series we will look at adding some interactivity using events and data binding with the help of Caliburn Micro.

Until next time, Happy Coding!

LightSpeed Book – now available!

tag icon Tagged as General, LightSpeed, News

I’m pleased to announce that LightSpeed developers everywhere can now purchase the official LightSpeed User Guide in printed form! Over 330 pages of useful advice and guidance on working with LightSpeed. The user guide acts as a great reference for your team and you will be sure to discover some gems to help improve your development experience even more.

Some of the topics covered:

  • Creating Domain Models
  • Basic operations with LightSpeed
  • Building web applications with LightSpeed
  • Controlling database mapping
  • Working with entities
  • Advanced querying
  • Search engine indexing
  • Much more

Pricing and availability

The eBook version is free – no charge. The physical version of the book is priced at $14.99 USD which covers production costs.

You can obtain either version from the Mindscape Lulu page.

Action shot

 
LightSpeed 4 User Guide Book
 

The summer sale is here!

Mindscape Summer Sale 2011

Note: This sale has now ended.

For our friends in the northern hemisphere it’s that time of the year – it’s warming up and there’s a holiday approaching. We thought it would be a great time to offer a special for the summer so that you have a great toolbox at your disposal for when you’re coding away on the beach.

Here’s the deal:

For the price of our WPF or Silverlight suites you can get a full Mindscape Mega Pack upgrade at no extra charge! And to save you money in the long run we’ll also add an additional six months of updates! Now that will afford you a few extra Mojitos!

So that’s every Mindscape product — WPF, Silverlight, Windows Phone, LightSpeed, SimpleDB, you name it — and 18 whole months of nightly builds, upgrades and entirely new products! All at a fraction of the price of other competing suites.

Throw on your skate shoes and roll over to the Summer Sale Page!

Greetings from a newbie Mindscaper

tag icon Tagged as General

Kia Ora everyone,

Hope all of you have had a fantastic easter break filled with loads of fun & greasy treats! I’ve been asked to introduce myself to the loyal blog followers since I’m new to the team here :-)

It has been so far an interesting first week here with the boys at the Mindscape office, working beside JD who demands perfection down to a single pixel has certainly giving me crossed eyes! I do wonder what lies ahead for the rest of the journey here…hehehe, no doubt there will be limitless laughter, music & food to share here, choice!

I am settling in ‘just’ comfortably on the production of web design, coming from a background of advertising and print design. My comfort zone…oh well, that might be down the drain by next week…. You can be expecting to see slight changes over the next few months on our website, we will be bringing you some spunky new site features and enhancements - starting with the buttons, back to work!

If you have any feedback on the site design please drop a comment below so I can make improvements!

Bye bye for now *[^.^]/
JC

A failed attempt at stopping spam bots

tag icon Tagged as General

I am spam man - I am here to annoy your users and hopefully sell some sweet herbal concoctions!

This post is just a quick overview of an experiment I ran recently with the Mindscape website. It’s nothing about our products but I thought the web devs out there might enjoy hearing this story. Late last year we upgraded our website and moved the core site over to MVC which made it nice and fun to develop with however we inadvertently opened the door to spambots.

We noticed that within a day or two that our forums were filling up with posts advertising cheap watches, viagra and adult links. Not something we really want and especially annoying since a lot of folks subscribe to forum update posts and would get this rubbish in their inbox. The obvious thing to do was to add either an email validation process (register -> not active until click link emailed to you) or add a captcha. Now, I hate captures and I hate email validation even more so I decided to try and think of how we could solve the problem.

1. Most spam bots will try and fill out every form field
I started by adding a hidden (as in display:none;) input box to the registration screen. If the controller action received a value for this friend then it was probably a bot and stated so in the validation field.

2. Most spam bots won’t execute JavaScript
I added a small script that dynamically added a new input box – also hidden – with a specific key value. If the controller action didn’t get this specific value back it could safely assume you were either a bot or you were running your browser with JavaScript disabled.

So how did this go? Generally pretty good – bot activity dropped to almost zero as we banned the existing accounts that posted dodgy links in our forum. Some of them were fairly cunning in that they lay dormant for months before finally posting, but we just deleted those accounts as they posted.

Then we ran a huge promotion and had thousands of folks registering on our website trying to claim a prize. Next thing you know we’re getting a bunch of unhappy people complaining our websites are calling them bots! Not an ideal situation at all. We finally tracked it down to the fact that most of those impacted were running form filling software (like 1Password) or had a browser that tried to complete the form (e.g. Google Chrome). When this happened those tools would dutifully assign values to the hidden input box that I mentioned as point 1. Not so good.

So, not wanting to continue to alienate people and still reduce spam in our forums I’ve relented and Jeremy recently switched the registration over to using Recaptcha for registrations and newsletter subscriptions. Speaking of which, why not test it out by subscribing to our newsletter? ;-)

I hope our experiment shared is useful for others thinking of ways to defeat spam bots.

Data Products Visual Controls Community Store
LightSpeed ORM
NHibernate Designer
SimpleDB Tools
SharePoint Tools
WPF Elements
WPF Diagrams
Silverlight Elements
Forums
Blog
Register
Login
Subscribe to newsletter
Buy Now
My Account
Volume Discounts
Purchase Orders
Contact Us