Posts
133
Comments
328
Trackbacks
0
July 2011 Entries
My eBook and articles series on OData for Silverlight and Windows Phone 7 is complete.

image

Introduction

I’m proud to announce my first eBook and update to my article series on OData for Silverlight and Windows Phone 7 is complete. I have worked very hard on this series and am pleased with the work. I may be a little biased, but I believe this is the best step-by-step guide ever created for OData and Silverlight/WP7 Mango. In the series, I walk you through every step with detailed screenshot and code snippets. From creating the OData data service to consuming it in an Silverlight application to performing CRUD operation in Windows Phone 7 Mango. The entire article series spans 63 pages and is divided into 4 chapters. I hope you enjoy reading it as much as I did writing it.

The Articles

All of the content of the e-Book is available free of charge to anyone who wants to learn. You can read any of the parts by clicking on the links below.

  1. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 1) – Creating our first OData Data Source and querying data through the web browser and LinqPad.
  2. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 2) – Consuming OData in a Silverlight Application.
  3. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 3)  – Consuming OData in a Windows Phone 7 Application (pre-Mango).
  4. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 4)  – Consuming OData in a Windows Phone 7 Application (Mango).

The e-Book:

This entire article series is available as an e-Book on SilverlightShow.net. It includes a .PDF/.DOC of the series with high resolution graphics and complete source code. See below for a table of contents:

Contents:

Chapter 1

Creating our first OData Data Source.
Getting Setup (you will need…)
Conclusion

Chapter 2

Adding on to our existing project.
Conclusion

Chapter 3

Testing the OData Data Service before getting started…
Downloading the tools…
Getting Started
Conclusion

Chapter 4

Testing and Modifying our existing OData Data Service
Reading Data from the Customers Table
Adding a record to the Customers Table
Update a record to the Customers Table
Deleting a record from the Customers Table
Conclusion

    alt Subscribe to my feed

    Posted On Thursday, July 28, 2011 6:50 AM | Feedback (1)
    From Soup to Nuts with the Surface 2.0 SDK

    image

    Continuing my “From Soup to Nuts” series or sometimes referred to as “The Busy Developers Guide” series, I will take a look at the Surface 2.0 SDK recently released by Microsoft.

    Before you read ahead, here are the other articles in this series:

    The Busy Developers Guide to the Kinect SDK Beta.
    The Busy Developers Guide to Mango.

    What is it?

    With the Microsoft® Surface® 2.0 SDK, you can easily create applications to take advantage of the next generation Surface computing device or any Windows touch-enables devices. (defined by Microsoft)

    Links worth checking out: (thanks to Luis Cabrera)

    Getting the SDK installed:

    After downloading the Surface 2 SDK, double click the installer on the SDK to get the ball rolling.

    SNAGHTML537a0db

    SNAGHTML538447a

    SNAGHTML538cf6a

    Getting the Runtime installed:

    Once that is complete then double click the installer for the Surface 2.0 Runtime.

    SNAGHTML53acf89

    SNAGHTML53b098c

    SNAGHTML53b611e

    A few things to note after installing it:

    Hit your Start button and go to your programs and navigate to the Microsoft Surface 2.0 SDK. You will notice the normal “Getting Help” and “Release Notes” but it also contains Surface Samples and Tools.

    image

    Surface Samples

    After clicking on that folder you will see a Surface Code Samples.zip file.

    SNAGHTML15b4225

    Go ahead and extract the zip file and you will notice the following sample project exist.

    SNAGHTML15e92b4

    Once loaded into Visual Studio 2010, you will see 14 projects exist inside of the solution.

    image

    Go ahead and set one of them as your “Startup Project”

    image

    You can now use your mouse or a touch-enabled monitor to interact with the application. You also have the full source code, so you can manipulate the application all you want.

    SNAGHTML163f9a1

    They have several other great examples of what the Surface 2.0 SDK is capable of.

    The Tools Folder:

    Inside the tools folder you will find the following applications.

    SNAGHTML166d83c

    Input Simulator - Simulate touch input and supported hardware parameters.

    According to the docs: (updated now for version 2.0)

    Surface Simulator replicates the user interface and behavior of a Microsoft Surface unit that is in user mode. Surface Simulator has access points, Launcher, and the loading screen. When you start an application in Surface Simulator, the application displays like it is on a Microsoft Surface unit.

    You can use Surface Simulator to evaluate how an application and its user interface respond to basic input. For example, if you simulate a painting application and if you touch multiple colors, one at a time, and then add the colors to a mixing bucket, you can test the logic of the application and how well it mixes the colors by using the touch-based interface.

    Surface Simulator runs with the appearance and functionality of a Microsoft Surface unit in user mode (the way that it appears to users). You can switch applications by using Launcher and the access points that display on the Launcher screen and the applications.

    image

    Input Visualizer - Display input data on top of a Microsoft Surface application.

    According to the docs:

    The Input Visualizer tool enables you to see the contact data that the Microsoft Surface Vision System returns in the context of your application. This tool runs on top of your application and displays information about the contacts that the input system detects.

    Input Visualizer can help you test and debug the following scenarios:

    • Accidental input: Track the accidental activation of Microsoft Surface controls from palms, forearms, and other objects by seeing when these controls detect contacts.
    • Contact tracking: Determine what gestures are lost as contacts when users are dragging content in Microsoft Surface applications. You can use the fade away feature of Input Visualizer for this type of tracking.
    • Input hit-testing: Investigate where hit-testing occurs by freezing the user interface of Input Visualizer, lifting contacts, and seeing where their centers are reported.

    Input Visualizer is installed with the Microsoft Surface SDK and runs only on Microsoft Surface units. If you are developing on a separate workstation, Surface Simulator provides contact visuals, reducing how much you need a visual representation of input.

    image

    Surface Stress - Open a command prompt window to run stress tests against a Microsoft Surface application.

    According to the docs:

    The Surface Stress tool enables you to test the stability and robustness of your Microsoft Surface application by delivering multiple, simultaneous contacts to your application in a random way. Surface Stress generates all four types of contacts: fingers, blobs, byte tags, and identity tags.

    Surface Stress is included with Microsoft Surface SDK 1.0 SP1. By default, the Surface Stress executable file (SurfaceStress.exe) is located in the C:\Program Files\Microsoft SDKs\Surface\v1.0\Tools\SurfaceStress folder, and a shortcut to Surface Stress appears in the Start menu under the Microsoft Surface SDK entry.

    SNAGHTML16f7e2b

    Let’s create a New Project.

    Now that you have learned how to download and get started with it then it is time to actually create a application. Go ahead and fire up Visual Studio 2010 and begin a new project. Look for Surface then v2.0.

    You will notice that you have 2 templates to start with.

    • Surface Application (WPF)
    • Surface Application (XNA Game Studio 4.0)

    SNAGHTML295b9

    We are only going to focus on the Surface Application (WPF)

    Go ahead and give your application a name and hit OK.

    image

    At first glance, you will realize this is just a WPF application. The folder structure looks just like what we would expect for a WPF application except that you have a “Resources” folder, a .xml document and MainPage.xaml is now called SurfaceWindow1.xaml.

    Let’s go ahead and take a look at the Toolbox. What we are most interested in is the “Surface Controls”. As you can see from this long list there is a lot of Surface specific controls at our disposal right off the bat.

    image

    Let’s go ahead and use the “SurfaceInkCanvas”. So drag and drop it onto the SurfaceWindow1.xaml file.

    Make sure your xaml looks very similar to the following:

    <s:SurfaceWindow x:Class="MichaelSurfaceApplication.SurfaceWindow1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="http://schemas.microsoft.com/surface/2008"
        Title="MichaelSurfaceApplication">
      <Grid>
            <s:SurfaceInkCanvas Name="SampleInkCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <s:SurfaceInkCanvas.DefaultDrawingAttributes>
                    <DrawingAttributes Color="#FF808080"/>
                </s:SurfaceInkCanvas.DefaultDrawingAttributes>
            </s:SurfaceInkCanvas>
        </Grid>
    </s:SurfaceWindow>

    Now go ahead and run your application and you should get the following screen. Go ahead and draw something on the screen and then close the window.

    image

    Congratulations! You just created your first Surface 2.0 application while actually writing no code. While you are probably testing it on your laptop or desktop this application would actually run on a Surface 2 Unit! Very cool stuff indeed.

    Conclusion:

    The Surface is very cool technology and I am planning on investing a lot of time into it and other things such as Kinect. Microsoft really got it right with the Surface 2.0 SDK. I think that this is possibly the best SDK release Microsoft has ever been a part of. The documentation is excellent, the samples are a plenty and it’s just plain easy to build your first application. Now if only I had an actual Surface 2 table in my house to play with then I would be really happy.

    alt Subscribe to my feed

    Posted On Monday, July 25, 2011 6:47 AM | Feedback (1)
    Razer DeathAdder 3500DPI Mouse Review

    WP_000064

    DISCLAIMER: I did not get this product for free. I bought it with my own money. However, if Razer wants to give me a keyboard for a review then I would gladly accept it. =)

    Official Product Page

    While I have been “Searching for the Perfect Developer’s Laptop” I have discovered that PC Gamers have it pretty good. For example, check out my “A Developers Review of Cooler Master Storm Laptop Cooler SF-19” article. Did you notice that this was a Gamers product? Developers actually have something in common with hardcore gamers. That is, we use our computers for hours on end and demand our hardware hold up. Gamers need the latest in computer hardware to play their games at the max resolution. We need the latest in computer hardware to compile our application in the shortest amount of time and because we are impatient while *anything* is loading =) Anyways, here is my review:

    Plug it in and install the software.

    After I got the mouse, I plugged it into my machine and instantly installed the Razer Software. I noticed right off the bat the mouse needed a firmware update. I hit the update button in the software and it send me to a website to download the proper firmware for my device. After I had the proper firmware I launched the software again and noticed how custom everything was.

    • You can adjust sensitivity, scroll speed, on-the-fly sensitivity and double-click speed by the options on the left hand side of the software.
    • You can rearrange the button assignment if needed.
    • You can even turn OFF the glow-logo or scroll button if the LED’s annoy you.

    (screenshot of the Razer DeathAdder driver software)

    image

    Why not use a standard or wireless mouse?

    Mark my words: I will NEVER use a wireless mouse again.  I’ve had it with low or dead batteries, obstacles in front of my receiver and Bluetooth driver problems. I will be using wired from now for better precision and no more batteries.  I’ve also had several standard wired mice ($10-$15) that feels just plain cheap when you click on the buttons. I’ve also experienced problems with the cables being bent over and over until the device does not function properly. With this device you actually feel like you have a quality product in your hands.

    PROS

    + It works flawlessly. No problems getting it setup and you don’t have to use their drivers if you don’t want too.

    + Comes with a long cord that is shielded for extra protection. The USB end is actually gold-plated.

    + Custom profile buttons at the bottom of the mouse allow you to create different profiles through the included software.

    + Comes with the ability to flash the firmware on the mouse to fix issues or add functionality.

    + 2 Year Warranty. – Nice to them stand behind their product.

    + Comes with a few stickers to put on your laptop or desktop.

    CONS

    - I really think that it should have come with a carrying case as most gamers / developers have to travel.

    WOULD I RECOMMEND IT TO MY FELLOW DEVELOPER? Absolutely, it has made such an impact on my computing experience that I would recommend it and a SSD to any developer.

    alt Subscribe to my feed

    Posted On Wednesday, July 13, 2011 6:21 AM | Feedback (0)
    Communicating between two local Silverlight Applications

    image

    Introduction

    One of the features that I’m surprised to see hardly no one talk about is “Communication Between Local Silverlight-Based Applications”. This is not new to Silverlight as it has been around since Silverlight 3. In other words, this will allow you to have two Silverlight applications running on the same PC talk to one another without using Web Services, etc. I originally was looking into this for a pet project that I was going to use with Kinect, but found this very valuable and decided to share with everyone. 

    Getting Started

    We are going to create two separate Silverlight Applications (select Silverlight 4 or 5 Beta). The First application that we are going to create is the receiver.

    Creating the Receiver

    Launch Visual Studio 2010 and create a new Silverlight Application and name it “SilverlightReceiver”.

    In your MainPage.xaml

    <Grid x:Name="LayoutRoot" Background="Yellow">
        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" Text="...Waiting for Message!" x:Name="txtReceiver"/>
    </Grid>

    In your MainPage.xaml.cs

    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Messaging;
    
    namespace SilverlightReceiver
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                Loaded += MainPage_Loaded;
            }
    
            void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                var messageReceiver = new LocalMessageReceiver("receiver", ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain);
                messageReceiver.MessageReceived += receiver_MessageReceived;
                
                try
                {
                    messageReceiver.Listen();
                }
                catch (ListenFailedException)
                {
                    MessageBox.Show(
                        "Cannot receive messages." + Environment.NewLine +
                        "There is already a receiver with the name 'receiver'.",
                        "LocalMessageReceiver", MessageBoxButton.OK);
                }
            }
    
            private void receiver_MessageReceived(object sender, MessageReceivedEventArgs e)
            {
                txtReceiver.Text = e.Message;
                e.Response = "Message received";
            }
        }
    }

    Your MainPage.xaml for your Receiver should look like this in design mode:

    image

    Creating the Sender

    Launch Visual Studio 2010 and create a new Silverlight Application and name it “SilverlightSender”.

    In your MainPage.xaml

    <Grid x:Name="LayoutRoot">
        <Button Content="Send a Message" Click="SendClick" Margin="10"/>      
    </Grid>

    In your MainPage.xaml.cs

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Messaging;
    
    namespace SilverlightSender
    {
        public partial class MainPage : UserControl
        {
            private LocalMessageSender _messageSender = new LocalMessageSender("receiver");
    
            public MainPage()
              {
                  InitializeComponent();
                  Loaded += MainPage_Loaded;
              }
    
            void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                _messageSender = new LocalMessageSender("receiver",LocalMessageSender.Global);
                _messageSender.SendCompleted += _sender_SendCompleted;
            }
      
              void _sender_SendCompleted(object sender, SendCompletedEventArgs e)
              {
                  MessageBox.Show("Response \"" + e.Response + "\" receieved.", "LocalMessageSender", MessageBoxButton.OK);
              }
      
              private void SendClick(object sender, RoutedEventArgs e)
            {
                _messageSender.SendAsync("Don't you love michaelcrump.net?");
             }
        }
    }
    Your MainPage.xaml for your Receiver should look like this in design mode:

    image

    Time to run it!

    Launch the receiver application first…

    SNAGHTML4d62506

    Then the sender application second…

    SNAGHTML4d6ee0f

    Click the “Send a Message” button and you should instantly get:

    SNAGHTML4d785cb

    Now click on your receiver application…

    SNAGHTML4d84294

    and you will see it now has the message you send from the “sender” application.

    Conclusion

    How cool is that? Plus it did not require any web services, etc! For future reference, you may want to check out the following pages on MSDN (where I grabbed some of the code for this demo).

    alt Subscribe to my feed

    Posted On Monday, July 11, 2011 6:16 AM | Feedback (2)
    I am now a Silverlight MVP as of July 2011.

    I found out last night that I have been awarded with the Microsoft MVP Award for my contribution to the Silverlight community. It is a honor, a privilege and one of the biggest moments in my professional life. I cannot tell you how excited that I am to be acknowledged by Microsoft for doing something that I love.

    According to Microsoft, this award is given by Microsoft to outstanding members of Microsoft's technical communities based on contributions made during the previous 12 months to offline and online Microsoft-related technical communities. Of 100 million technical community participants worldwide, about 5,000 are MVPs. Outstanding technical community members are nominated by their peers, Microsoft employees, and MVPs. Each year a panel of Microsoft employees reviews the contributions of each nominee for quality, quantity, and level of impact on the technical community.

    I would like to say thanks to Microsoft for giving me this award, my friends, family, co-workers, blog readers, other community leaders and everyone else who has encouraged me and supported my efforts.

    So, why did you wait so late to tell us?

    I can hear your tweets, DM’s and emails so let me tell you now. It is because the email address that Microsoft had was incorrect. My MVP Lead corrected it last night and I just got the email.

    Thanks again to everyone,

    alt Subscribe to my feed

    Posted On Wednesday, July 06, 2011 5:28 AM | Feedback (7)
    Kinecting the Dots: Adding Buttons to your Kinect Application

    image

    Introduction

    The official Kinect SDK has been out for a while now and I haven’t seen many people actually doing “how-to” post to get others started developing for it. I decided that I would help kick-start the movement by creating a series called, “Kinecting the Dots”. This is going to be a series of blog posts covering questions or concerns that I’ve seen in the community.  I am planning on answering questions so if  you have one that you want answered then please contact me by using the form above.

    First a few post by me that will help you get started developing for Kinect. I highly recommend the first one.

    The busy developers guide to the Kinect SDK Beta
    3 Incredibly Useful Projects to jump-start your Kinect Development.

    Question:

    How do you get create a button that can be used in your Kinect Applications? I would like my users to be able to interact with it inside of the application.

    Answer:

    There are a lot of ways you can implement a custom button that your user can interact with in a Kinect Application. The one that we are going to do today is part of the Coding4Fun Kinect Toolkit. This toolkit provides a button called “Hover Button”. The only problem is that some people can’t figure it out because it does not have any documentation.

    Let’s get started:

    Download and install the following software.

    The  official Kinect for Windows SDK beta – You can either download a 32 or 64 bit SDK depending on your OS.
    Coding4Fun Kinect Toolkit – Lots of extension methods and controls for WPF and WinForms – we are only interested in the Hover Button at this point.
    KinectContrib is a set of VS2010 Templates that will help you get started building a Kinect project very quickly.
    GUI Buttons for Active/Hover – Not required but some great sample buttons with a free license on them.

    Source Code to Sample Application

    If you just want the source code to this application then it is located here.

    Fire up Visual Studio

    Start Visual Studio 2010 SP1 and go to File-> New Project and select Windows->Kinect->KinectSkeletonApplication. You can go ahead and give it a name if you wish.

    SNAGHTMLb7b7ec

    As soon as the project loads, we are going to add a reference to add a reference to the Coding4Fun Kinect Toolkit file named Coding4Fun.Kinect.Wpf.dll. You should have these files if you downloaded the Coding4Fun Kinect Toolkit mentioned earlier.

    SNAGHTML169f157

    Since we are going to add some buttons to our project. Let’s go ahead and download some premade button images that have a active and inactive state. I used the pack from here.

    Create a folder in your project named “Resource” and copy all of the buttons to that folder. We are only going to use one set, but you may find the others useful later. Your solution should look like this:

    image

    XAML

    This template comes with a lot of code to get started already. We are simply going to add the Hover Button and it’s namespace. Our MainPage.xaml should look like the following once complete:

    <Window x:Class="KinectingTheDotsUserControl.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:Coding4Fun.Kinect.Wpf.Controls;assembly=Coding4Fun.Kinect.Wpf" Title="MainWindow" Height="600" Width="800">
        <Grid x:Name="theGrid">
            <Image Name="videoImage"></Image>
            <Canvas Background="Transparent">
                <Ellipse Fill="Red" Height="20" Width="20" Name="leftHand" Stroke="White" />
                <Ellipse Fill="Red" Height="20" Width="20" Name="rightHand" Stroke="White" />
                <Ellipse Fill="Red" Height="20" Width="20" Name="head" Stroke="White" />
                <Controls:HoverButton x:Name="kinectButton" ImageSize="100" ImageSource="/Resources/RedButton-Hover.png"  ActiveImageSource="/Resources/RedButton-Active.png" IsTriggeredOnHover="True" Canvas.Left="631" Canvas.Top="34" />
            </Canvas>
        </Grid>
    </Window>

    We set the initial ImageSource and the ActiveImageSource on the Hover Button. We also set the IsTriggeredOnHover to true to Trigger the button when something is hovered onto it.

    CODE BEHIND

    Now let’s add some code behind. I am only going to display the code that I added. This template comes with the skeleton code already in place.

    Please NOTE that I grabbed a chunk of code out of the Jellybean project located here for this demo.

    First things First

    I added a Click Event handler for the Hover Button.

     kinectButton.Click += new RoutedEventHandler(kinectButton_Clicked);

    Then I wired up my event handler as shown below.

    void kinectButton_Clicked(object sender, RoutedEventArgs e)
    {
       TextBlock textBlock = new TextBlock();
        textBlock.Text = "Triggered";
        textBlock.FontSize = 42;
        theGrid.Children.Add(textBlock);
    }

    This is simply going to throw a TextBlock onto the Grid and display the word “Triggered”.

    I then took JellyBean’s code for “CheckButton” and eliminated the UserControl and used the Ellipse that is included in the KinectContrib Skeleton Template.

    private static void CheckButton(HoverButton button, Ellipse thumbStick)
    {
        if (IsItemMidpointInContainer(button, thumbStick))
        {
            button.Hovering();
        }
        else
        {
            button.Release();
        }
    }


    I then took the next two methods directly out of the JellyBean project as they will determine if an Item is MidPoint in a Container.

    public static bool IsItemMidpointInContainer(FrameworkElement container, FrameworkElement target)
    {
        FindValues(container, target);
    
        if (_itemTop < _topBoundary || _bottomBoundary < _itemTop)
        {
            //Midpoint of target is outside of top or bottom
            return false;
        }
    
        if (_itemLeft < _leftBoundary || _rightBoundary < _itemLeft)
        {
            //Midpoint of target is outside of left or right
            return false;
        }
    
        return true;
    }
    
    
    private static void FindValues(FrameworkElement container, FrameworkElement target)
    {
        var containerTopLeft = container.PointToScreen(new Point());
        var itemTopLeft = target.PointToScreen(new Point());
    
        _topBoundary = containerTopLeft.Y;
        _bottomBoundary = _topBoundary + container.ActualHeight;
        _leftBoundary = containerTopLeft.X;
        _rightBoundary = _leftBoundary + container.ActualWidth;
    
        //use midpoint of item (width or height divided by 2)
        _itemLeft = itemTopLeft.X + (target.ActualWidth / 2);
        _itemTop = itemTopLeft.Y + (target.ActualHeight / 2);
    }

    The very last thing to do was wire CheckButton inside of the SkeletonFrameReady event.

    CheckButton(kinectButton, rightHand);

    This will simply allow me to tie the rightHand Ellipse to the kinectButton that I placed on the Canvas earlier.

    THE APPLICATION

    You will see we have a Kinect Application with three red ellipse.

    1. Head
    2. Left Hand
    3. Right Hand

    When my right hand moved the Red Ellipse over the Hover Button it triggered the click event handler and displayed the TextBlock with the text “Triggered” in it.

    image

    I can now make a button more similar to the official ones used in the XBOX Kinect Games by using the following XAML.

     <Controls:HoverButton x:Name="kinectButton" ImageSize="100" ImageSource="/Resources/RedButton-Hover.png"  ActiveImageSource="/Resources/RedButton-Active.png" TimeInterval="3000"  Canvas.Left="631" Canvas.Top="34" />

    image

    As the user hovers over the button the white bar will begin to fill. Once it hits 100% then your “Click” event will fire.

    Conclusion

    It really is amazing what you can do with the Kinect SDK so far. I believe in a few months things will get even easier. I hope this helps kick-start your Kinect Development.

    Full Source Code is provided here.

    alt Subscribe to my feed

    Posted On Monday, July 04, 2011 9:10 AM | Feedback (0)
    Tag Cloud