Showing posts with label Surface Development. Show all posts
Showing posts with label Surface Development. Show all posts

Tuesday, June 9, 2009

Deploying applications in Microsoft Surface SP1

The surface has a launcher application which is launching applications registered with the Surface Shell.Launcher can be activated from any of the 4 access points located at corners of surface.

Registering Microsoft Surface Application
To register an application with Microsoft surface shell we have to copy the application’s xml definitions file into the %PROGRAMDATA%\Microsoft\Surface\Programs folder.This is the folder where surface looks for application definitions.It maintains a list of applications listed here to load on demand by launcher.

Application’s definition file is a simple xml file which describes the application.Common elements included in the definition are

Title : Title  of the application
Description:Description about application
Executable: Path to exe.Path need to be absolute.
IconImageFile:Icon of application.
Preview: Preview images

A sample 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>Test Surface App</Title>
<Description>This is a test Surface application.</Description>
<ExecutableFile>%ProgramData%\Microsoft\Surface\Programs\SurfaceApplication1.exe</ExecutableFile>
<Arguments></Arguments>
<IconImageFile>%ProgramData%\Microsoft\Surface\Programs\Resources\icon.png</IconImageFile>
<Preview>
<PreviewImageFile>%ProgramData%\Microsoft\Surface\Programs\Resources\iconPreview.png</PreviewImageFile>
</Preview>
</Application>
</ss:ApplicationInfo>

Saturday, May 30, 2009

Changing the Orientation or Surface application

Surface supports orientation of applications to 2 sides according to the seating position of the user.If we are developing applications we have to rotate our applications our self.Its done by checking the static property Microsoft.Surface.ApplicationLauncher.Orientation.
There is an event called Microsoft.Surface.ApplicationLauncher.OrientationChanged which fires when the user changes his side by clicking on the access buttons at the corresponding side.

Setting the Orientation
We need to have a RotateTransform in our application whose Angle ,we are going to change according to the Orientation.Normally we place the RotateTransform in the root element of the SurfaceWindow.

<s:SurfaceWindow x:Class="SurfaceApplication1.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="SurfaceApplication1">
<Grid Name="MenuGrid">
<Grid.LayoutTransform>
<RotateTransform x:Name="OrientationTransform" Angle="0"/>
</Grid.LayoutTransform>
<TextBlock Name="OrientationTextBox" HorizontalAlignment="Center"/>
</Grid>
</s:SurfaceWindow>



Subscribe to the ApplicationLauncher.OrientationChanged event and set the Angle as per the ApplicationLauncher.Orientation property.

private void AddActivationHandlers()
{
// Subscribe to surface application activation events
ApplicationLauncher.ApplicationActivated += OnApplicationActivated;
ApplicationLauncher.ApplicationPreviewed += OnApplicationPreviewed;
ApplicationLauncher.ApplicationDeactivated += OnApplicationDeactivated;
ApplicationLauncher.OrientationChanged += ApplicationLauncher_OrientationChanged;
}
void ApplicationLauncher_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
OrientationTransform.Angle = ApplicationLauncher.Orientation == UserOrientation.Top ? 180 : 0;
OrientationTextBox.Text = ApplicationLauncher.Orientation.ToString();
}



Using Triggers to change the Orientation or Surface application based on ApplicationLauncher.Orientation.

Its clear like water that we can’t use EventTrigger to set the Angle of Transform.Another method is PropertyTrigger.Since the ApplicationLauncher.Orientation is not an AttachedProperty we can’t use that method too.Simply saying we have to write code in order to achieve.I am searching for a method which does the same using xaml alone.If anybody finds,please share with me.

Wednesday, May 20, 2009

Introducing Surface SP1

The first Service pack for Microsoft surface has released on May 10.It has got significant changes comparing to the older older.Here are the main features I noticed.

  1. New controls
    1. ElementMenu
    2. LibraryBar
  2. Tagged object routing
  3. Improved contact visualization
  4. Improved access points

More details here
http://blogs.msdn.com/surface/archive/2009/05/11/service-pack-1-officially-released-today.aspx
http://arstechnica.com/microsoft/news/2009/05/microsoft-surface-sp1-adds-new-features.ars

As a developer, I am more interested in the new controls and will be posting about them later.

Friday, May 8, 2009

Using TagVisualizer and TagVisualization in Surface development

This post describes about the programming aspects of Surface tags.If you are not familiar with surface and surface tags please see posts below

Surface Application Development using Simulator and VisualStudio.
Identifying Finger ,Tag and Blob in Surface using Contacts class

TagVisualizer

TagVisualizer is a ContentControl derived from SurfaceContentControl and it’s basic function is to show Tag Visualizations when the corresponding tag is placed on the surface. Tag Visualizations are added by means of TagVisualizationDefinition.For that the TagVisualizer has a property called Definitions which is of type TagVisualizationDefinitionCollection.Each TagVisualizationDefinition tells what to display when a tag is being placed.

TagVisualizationDefinitions

This defines the visual against the tag value.The visual can be a UserControl and it is mentioned in the form of Uri.There are 2 types of tags in surface as you know.So there should be a mechanism to differentiate these tags while displaying.The method here used here is inheritance.ByteTagVisualizationDefinition  which is derived from abstract class TagVisualizationDefinition deals with the byte tags and IdentityTagVisualizationDefinition derived from same ,deals with Identity tags.A simple xaml code which shows a red colored usercontrol on byte tag of value 10 is shown below.

<Grid Background="{StaticResource WindowBackground}">
<s:TagVisualizer>
<s:TagVisualizer.Definitions>
<s:ByteTagVisualizationDefinition Value="10"
Source="ByteTagVisualization.xaml">
</s:ByteTagVisualizationDefinition>
</s:TagVisualizer.Definitions>
</s:TagVisualizer>
</Grid>


<UserControl x:Class="SurfaceApplication1.ByteTagVisualization"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" Background="Red">
<Grid>

</Grid>
</UserControl>

ByteTagVisualization is a normal UserControl available in WPF.Hope this is clear like water.Shows the UserControl ByteTagVisualization when we place a byte tag with value 10 in the area covered by TagVisualizer.


TagVisualization


This is again a ContentControl which can be used as Source in TagVisualizationDefinition.The advantage here is that, the TagVisualization class has some properties which are related to the tag and tag data.Below goes steps which explains how to create TagVisualization.


  1. Create a UserControl

  2. In the xaml file change the root tag as s:TagVisualization where s is xmlns:s="http://schemas.microsoft.com/surface/2008" namespace of surface controls.

  3. In the xaml.cs file change the base class to TagVisualization.Also change the constructor to suit the class.


A sample TagVisualization is given below



<s:TagVisualization x:Class="SurfaceApplication1.IdentityTagVisualization"
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">
<StackPanel>
<TextBlock>An Identity tag has been placed</TextBlock>
</StackPanel >
</s:TagVisualization>

Getting tag values in TagVisualization and databinding


Even though the TagVisualization has the Property TagData we can’t use that in binding because that is not WPF friendly.



<TextBlock  Text="{Binding VisualizedTag.Type,ElementName=tagVisualization}" />

The above code won’t work

To enable databinding in TagVisualization we have to write our own properties which are data bindable.Then to get the value of tag which is placed over TagVisualizer override the OnGotTag method and get value from VisualizedTag property.



public partial class IdentityTagVisualization : TagVisualization
{
public long? TagValue
{
get { return (long?)GetValue(TagValueProperty); }
set { SetValue(TagValueProperty, value); }
}
public static readonly DependencyProperty TagValueProperty =
DependencyProperty.Register("TagValue", typeof(long?), typeof(IdentityTagVisualization));

public IdentityTagVisualization()
{
InitializeComponent();
}
protected override void OnGotTag(RoutedEventArgs e)
{
if (VisualizedTag != null)
{
TagValue = (VisualizedTag.Type == TagType.Byte) ?
VisualizedTag.Byte.Value :
VisualizedTag.Identity.Value;
}
base.OnGotTag(e);
}
}
}

Now you can databind the value of the tag in xaml.



<s:TagVisualization x:Class="SurfaceApplication1.IdentityTagVisualization"
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" x:Name="tagVisualization">
<StackPanel>
<TextBlock>Tag has been placed value is </TextBlock>
<TextBlock Text="{Binding TagValue,ElementName=tagVisualization}" />
</StackPanel >
</s:TagVisualization>

Download sample from here.

Thursday, May 7, 2009

Identifying Finger Tag and Blob in Surface using Contacts class

If you are not much familiar with Microsoft surface just have a look here in my another blog and get start in Surface development from here.

There is an attached event called ContactDown in the class Contacts.We can subscribe to that in any visuals and process according to that.

<s:SurfaceWindow x:Class="SurfaceApplication.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">
<Grid>
<TextBlock>Place contact here</TextBlock>
<Rectangle Grid.Row="1" Fill="#0fff0000"
Width="100" Height="100" s:Contacts.ContactDown="Rectangle_ContactDown" />
</Grid>
</s:SurfaceWindow>











Code behind





private void Rectangle_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
{
if (e.Contact.IsTagRecognized)
{
switch(e.Contact.Tag.Type)
{
case Microsoft.Surface.Presentation.TagType.Byte:
MessageBox.Show(string.Format("Byte tag identified value={0}", e.Contact.Tag.Byte.Value));
break;
case Microsoft.Surface.Presentation.TagType.Identity:
MessageBox.Show(string.Format("Identity tag identified value={0}", e.Contact.Tag.Identity.Value));
break;
}
return ;
}
if (e.Contact.IsFingerRecognized)
{
MessageBox.Show("Finger contact identified");
}
else
{
MessageBox.Show("Blob identified");
}
}









This code just shows a message box. Processing the contacts such as showing something upon placing a contact and all will be discussed later in the post ‘Using TagVisualizer and TagVisualization’.