My Blog is Moving

May 10, 2009

Hello valued readers,

I am moving my blogging efforts over to:

http://geekswithblogs.net/robertbunn/Default.aspx

See you there!

Bob

Advertisements

Combining Byte Tags to Get Beyond the 256 Limit

May 7, 2009

I was working with identity tags and byte tags today, and the obvious short-comings of both became apparent to me.  The identity tags have an enormous number of unique values possible, but there is no tool to create them right now.  The byte tags can be created and printed now quite easily, however there is only 256 different possibilities when using a single byte tag.  So I threw together a way to add multiple byte tags onto a single object to create far more possible values.  4 byte tags together will give about 4 billion unique values.  One thing to remember is that you can’t be sure which byte tag the surface will recognize first, so you need to employ permutations of byte tags here, not combinations.  For example, “0D” and “DD” is the same as “DD” and “0D”.  Anyhow, I just came up with the concept and threw something together, so there are many ways to improve this sample I’m sure.  Download the sample then rename the .doc extension to .zip before unzipping the files.  If you improve upon this please send me a copy if you can and I will share it with everyone, giving credit where it is due as well.

multibytetagsample


Packaging Microsoft Surface App for Deployment

May 6, 2009

After months of development I finally got around to packaging up my app for deployment in user mode on the Surface.  I did run into a couple of minor hurdles at first which I will share with you, and tell you how I got around them.  First of all, check out the documentation on the Microsoft Surface community site and the SDK.  In your root app directory you will see a file like myapp.xml which is generated by visual studio for you.

The following code example shows the default XML file.

<?xml version="1.0" encoding="utf-8" ?>
<ss:ApplicationInfo
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:ss="http://schemas.microsoft.com/Surface/2007/ApplicationMetadata">
  <Application>
    <Title>SurfaceApplication</Title>
    <Description>SurfaceApplication</Description>
    <ExecutableFile>SurfaceApplication.exe</ExecutableFile>
    <Arguments></Arguments>
    <IconImageFile>Resources\icon.png</IconImageFile>
    <Preview>
      <PreviewImageFile>Resources\iconPreview.png</PreviewImageFile>
    </Preview>
  </Application>
</ss:ApplicationInfo>

Notice in the <ExecutableFile> element, how it has “SurfaceApplication.exe” as the value?
It should really look like this:

%ProgramFiles%\Microsoft Surface\SurfaceApplication\SurfaceApplication.exe
The urls in your other elements like the previewIcon should follow the same format. Hopefully, this helps some people out.


Converting WPF Apps to Surface Apps – Part 1

April 18, 2009

I have found myself converting WPF apps to Surface apps quite often lately.  Most of the necessary changes are fairly obvious, but I encountered one lately I thought I would share with you.  In WPF apps there is functionality to capture the mouse cursor, but in Surface we have no mouse.  So we need to perform the analogous catch of a finger (or whatever else you like) contact.  Below is the first method I needed to change in a recent project:

private void OnMouseDown(object sender, MouseButtonEventArgs args)

{

UIElement source = sender as UIElement;

Point p = args.GetPosition(source);

if (a boolean)

{

this.CaptureMouse();

}

else

return;

}

By the way, “this” is a ContentControl.  Notice the this.CaptureMouse() line?  Clearly this needs to change for surface.  There is no this.CaptureFinger() on a SurfaceContentControl (that would be way too easy).  So I modified the above code to the following:

private void SurfaceContentControl_ContactDown(object sender, ContactEventArgs e)

{

UIElement source = sender as UIElement;

Point p = e.GetPosition(source);

if (a boolean)

{

e.Contact.Capture(this);

}

else

return;

}

So in this case I switched:

this.CaptureMouse();
for this:

e.Contact.Capture(this);

That was easy enough.  Let’s try another.

private void OnMouseMove(object sender, MouseEventArgs args)

{

UIElement source = sender as UIElement;

Point p = args.GetPosition(source);

if (!(sender as UIElement).IsMouseCaptured)

{

//Do some stuff

}

}

Which I changed to:

private void SurfaceContentControl_ContactChanged(object sender, ContactEventArgs e)

{

UIElement source = sender as UIElement;

Point p = e.GetPosition(source);

if ((sender as UIElement) != e.Contact.Captured)

{

//Do some stuff

}

}

So in this case I changed:

if (!(sender as UIElement).IsMouseCaptured)
into this:

if ((sender as UIElement) != e.Contact.Captured)

We’re on a roll here, let’s do another:

private void OnMouseUp(object sender, MouseButtonEventArgs args)

{

if (this.IsMouseCaptured)

{

UIElement source = sender as UIElement;

Point p = args.GetPosition(source);

if (a boolean)

//Do something

this.ReleaseMouseCapture();

}

}

Turns into this:

private void SurfaceContentControl_ContactUp(object sender, ContactEventArgs e)

{

if (this.IsAnyContactCaptured)

{

UIElement source = sender as UIElement;

Point p = e.GetPosition(source);

if (a boolean)

//Do something


this.ReleaseAllContactCaptures();

}

}

Now you know how to change mouse capture logic in old WPF apps into new finger capture logic.  Please feel free to comment if you know how I could improve this.


WPF Developer Wanted – Microsoft Surface Development

April 14, 2009

Hello everyone,

The company I work for CSG in Denver, CO is looking for WPF developers to work on Microsoft Surface projects.  No experience with Microsoft Surface is necessary, just WPF.  Any knowledge of XNA would be helpful, but not necessary.  If this interests you please send your inquiries or resume to hiring [at] csgresults [dot] com

Bob


Microsoft Surface – Drag and Drop Tutorial Series – Part 2

April 13, 2009

This is Part 2 of my series on implementing drag and drop in Microsoft Surface.  In part 1, we created a Surface Window with a Surface ListBox and a ScatterView in it.  We hooked up our ListBox to a data source of products coming from Amazon.com.  Now we will get to the good stuff and make drag and drop a reality in our application!

I posted this tutorial on The Code Project since it was easier to deal with the download and formatting issues there.  Please see the article at:

http://www.codeproject.com/KB/WPF/SurfaceAppTutorialPart2.aspx


Microsoft Surface – Drag and Drop Tutorial Series – Part 1

April 11, 2009

This is going to be part 1 of a multi-part tutorial on how to implement drag and drop on Microsoft Surface.  In this part we will add a Surface ListBox and a ScatterView to our Surface Window as the basic controls we will need here.  We will also show how to use the Amazon.com web service to populate your list box with anything you like.  We will not get into performing drag and drop in this part, we will simply set ourselves up to do this starting in Part 2 of this series.

I moved this tutorial to The Code Project since it was much easier to deal with downloads and code formatting there.  Please check out this tutorial at:

http://www.codeproject.com/KB/WPF/SurfacAppPart1.aspx