Up Getting started
DevForce Resource Center » Punch » Getting started » Hello World (Silverlight)

Hello World (Silverlight)

Last modified on January 26, 2015 11:43
  1. Start by creating a blank Silverlight 5 project. Go to "File|New|Project..." and name the project HelloWorld.SL.


    FileNewSilverlight.PNG

  2. Leave all the defaults on the next screen.


    NewSilverlightApp.PNG

  3. Delete MainPage.xaml. We won't need it.

  4. Install the Punch NuGet package. Go to "Tools|Library Package Manager|Package Manager Console", enter and run the following command.
    PowerShell
    Install-Package IdeaBlade.Cocktail -ProjectName HelloWorld.SL
  5. Install the DevForce 2012 Server NuGet package. We won't need this quite yet, but it's good practice to get the server ready now. From the Package Manager Console, enter and run the following command.
    PowerShell
    Install-Package IdeaBlade.DevForce.Server -ProjectName HelloWorld.SL.Web
  6. Create a ViewModel. Add a new class to your project, name it MainViewModel and replace the contents of the file with the following. Learn more about ViewModels here.
    C#
    using System.ComponentModel.Composition;
    using System.Threading.Tasks;
    using Cocktail;

    namespace HelloWorld.SL
    {
        [Export]
       public class MainViewModel
        {
           private readonly IDialogManager _dialogManager;

            [ImportingConstructor]
           public MainViewModel(IDialogManager dialogManager)
            {
                _dialogManager = dialogManager;
            }

           public async Task SayHello()
            {
                await _dialogManager.ShowMessageAsync("Hello World!", DialogButtons.Ok);
            }
        }
    }
  7. Create a View. Right-click on the project, select "Add|New Item..." and then Silverlight User Control. Name it MainView.xaml.


    NewViewSL.PNG

  8. Replace the contents of the file with the following.
    XAML
    <UserControl x:Class="HelloWorld.SL.MainView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 mc:Ignorable="d"
                 d:DesignHeight="300" d:DesignWidth="400">

        <Grid>
            <Button Content="Say Hello" x:Name="SayHello" />
        </Grid>
    </UserControl>
  9. Create a bootstrapper. Add a new class to your project, name it AppBootstrapper and replace the contents of the file with the following. Learn more about bootstrapping here.
    C#
    using Cocktail;

    namespace HelloWorld.SL
    {
       public class AppBootstrapper : CocktailMefBootstrapper<MainViewModel>
        {
        }
    }
  10. Open App.xaml and replace the contents of the file with the following.
    XAML
    <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:HelloWorld.SL"
                 x:Class="HelloWorld.SL.App"
                 >
        <Application.Resources>
            <local:AppBootstrapper x:Name="bootstrapper" />
        </Application.Resources>
    </Application>
  11. Open App.xaml.cs and replace the contents of the file with the following to get rid of the unnecessary default template code.
    C#
    using System.Windows;

    namespace HelloWorld.SL
    {
       public partial class App : Application
        {
           public App()
            {
                InitializeComponent();
            }
        }
    }
  12. Build and run. Congratulations, you just created your first application with Punch.

  13. Next steps, learn about adding a Model, the EntityManager, EntityManagerProvider and the Unit of Work Pattern or proceed with our Happy Hour Tutorial and the TempHire reference application.

Tags:
Created by DevForce on December 20, 2012 11:32

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade