Adding / Removing the Multi-Touch Blend Behavior using C# code-behind
I’ve received several requests about the modalities of enabling multi-touch on a UI element using the Behavior available on my CodePlex project.
The traditional syntax using XAML is here:
<Image Source="Images/Desert.jpg" x:Name="image1">
<interactivity:Interaction.Behaviors>
<Silverlight4:MultiTouchBehavior
IsInertiaEnabled="True"
IsTranslateXEnabled="True"
IsTranslateYEnabled="True"
IsRotateEnabled="True"
IsScaleEnabled="True"
MinimumScale="10" MaximumScale="100"
AreFingersVisible="True"/>
</interactivity:Interaction.Behaviors>
</Image>
What about if you want to achieve the same result using C#? Just obtain a collection of behaviors for your element and then add/remove the MultiTouchBehavior using the following syntax:
private void btnAttach_Click(object sender, RoutedEventArgs e)
{
var behaviors =
System.Windows.Interactivity
.Interaction.GetBehaviors(image1);
behaviors.Clear();
var mtb = new MultiTouchBehavior
{
IsRotateEnabled = true,
IsScaleEnabled = true,
IsTranslateXEnabled = true,
IsInertiaEnabled = true,
AreFingersVisible = true,
MinimumScale = 20,
MaximumScale = 200
};
behaviors.Add(mtb);
mtb.Move(new Point(200, 150), 45, 100);
}
private void btnDetach_Click(object sender, RoutedEventArgs e)
{
var behaviors =
System.Windows.Interactivity
.Interaction.GetBehaviors(image1);
if (behaviors.Count > 0)
{
behaviors.Clear();
}
}
As usually the source code is available for download on the Multi-Touch CodePlex project (check out the SilverlightWP7MultiTouch Solution).
Oh, did I already say that it also works on Windows Phone 7?
Happy Silverlighting!
Duplex sample updated to Silverlight 4
I was following this thread on the Silverlight forums and was asked to update the Duplex sample to Silverlight 4.
Click here to download the code.
More information about Duplex Services are available here:
- http://msdn.microsoft.com/en-us/library/cc645027(VS.95).aspx
- http://msdn.microsoft.com/en-us/library/ee844557(v=VS.95).aspx
Happy Silverlighting!
NDepend v3.2.0 available: Visual Studio Integration and Contextual-Sensitive help
Check out this new article by Patrick Smacchia about the new Contextual-Sensitive help feature in NDepend v3.2.0.
More details about NDepend (which now supports Visual Studio full integration) are available here:
Register for the Silverlight Firestarter!

Light up your Silverlight skills with the all-new Global Silverlight Firestarter!
What is the Silverlight Firestarter?
- An Event: A one day, global, live streamed and on demand event keynoted by Scott Guthrie
- Training: New self-paced labs and walk through videos
- Interactive: Got questions? Get your answers! Watch live and ask the Silverlight product team questions during the event.
- Why Silverlight? Silverlight is Microsoft’s strategic development platform for building interactive applications across desktop, phone, and the browser.
Something for Everyone
- Just starting out with Silverlight? Watch our On-Ramp sessions and work on hands on labs to get you started.
- Already Building business applications? Watch the event live and learn how to create compelling business applications with Silverlight.
- Got questions? Engage with the Silverlight product team live or in person with our interactive chat.
| When | Register | How Much? |
| December 2, 2010 8am to 5pm PT | Register Online, Now! | Nothing! This is a free event |
After the live event keep fueling the fire!
Dive deeper with additional hands on labs and videos that build on the live session content, accelerating you ahead of the crowd.
- Watch the entire event on demand!
- Plus, new self-paced labs and walk through videos
- On Ramp Labs (100 level)
- Hands on labs specifically focused on helping new developers get up to speed quickly on Silverlight
- Do you know WinForms? HTML? ASP.NET? Want to learn Silverlight? We have a lab for you!
- Building Better Business Apps (200-300 level)
- Hands on labs focused on taking advantage of Silverlight to build real world business applications
- Apply Data Strategies, Patterns, Out of Browser, RIA Services, and much more using Silverlight
- Turnabout is fair play! Watch a video of our experts doing the labs themselves.
| F I R E S T A R T E R L I V E A G E N D A | |||
| 8:00 am | Silverlight Firestarter Keynote | Scott Guthrie | |
| 9:00 am | Masterful Data Strategies with Silverlight and WP7 | Jesse Liberty | |
| 10:00 am | 15 minute break | ||
| 10:15 am | Roll Out Your Business Apps Today with RIA Services | Pete Brown | |
| 11:15 am | MVVM: Why and How? Tips and Patterns using MVVM and Service Patterns | John Papa | |
| 12:15 pm | Lunch break | ||
| 1:00 pm | Silverlight Today and Tomorrow (Special Guest Panel) | Panel | |
| 1:30 pm | Building Real World Silverlight Apps | Tim Heuer | |
| 2:30 pm | 15 minute break | ||
| 2:45 pm | Tune Your Application: Profiling and Performance Tips | Mike Cook & Jossef Goldberg | |
| 3:45 pm | Killer Performance Tips for Silverlight Windows Phone 7 | Jaime Rodriguez | |
| 5:00 pm | After Party! | ||
*** Sessions are subject to change
Spread the Word!
- Blog and tweet to spread the word about the Firestarter!
- Ask people to add the Twitter hash tag #slfs10 to their tweets
- Use the banners and blog bling (attached)
Questions
Got questions? Ask slfs@microsoft.com
MEF Contrib is live!
Check out this great resource for MEF (Managed Extensibility Framework developers:
From the main site:
MefContrib is a community-developed set of extensions, tools and samples for the Managed Extensibility Framework (MEF).
The project is an open source project, licensed under the MS-PL license. MefContrib is about YOU. With your help we can make it a vibrant resource for MEF developers world-wide.
MEF Contrib is the one stop shop for all your MEF needs. Within you’ll find:
- Community extensions to MEF like support for convention based registration, open generics and AOP.
- Tools like Visual MEFX, a tool for diagnosing composition
- Guidance, Quickstarts and Samples to help you learn the ropes from experts
Windows Phone 7 Developer Tools and Silverlight for Windows Phone 7 Toolkit released
- Silverlight for Windows Phone – Silverlight.net Get Started
- Windows Phone 7 – Released To Manufacturing – Windows Phone Blog
Downloads:
Blog posts:
Happy Silverlighting with Windows Phone!
Windows Phone 7: Touch-based Gestures API in XNA Game Studio 4.0
Check out this great sample available in the XNA community site.
It includes code that uses the Gestures API to enable hold, drag, tap, flick, pinch gestures.
Windows Phone 7, Multi-Touch Behaviors and the Surface samples for Silverlight
I’ve just finished some experiments using the Windows Phone 7 emulator and the “Microsoft Surface Manipulations and Inertia Sample for Microsoft Silverlight” in order to enable Multi-Touch gestures using Blend Behaviors:
This new implementation, now available for download in the Expression Gallery, permits to enable Multi-Touch gestures (the usual translation, rotation, zoom and inertia) on separate User Controls available in the same container.
In this way you can apply distinct Multi-Touch manipulations (inertia included) to single elements using a single code in xaml:
<Grid x:Name="ContentPanel" Grid.Row="1">
<Canvas>
<Image Source="Images/Desert.jpg" x:Name="image1">
<interactivity:Interaction.Behaviors>
<WP7:MultiTouchManipulationBehavior IsInertiaEnabled="True" IsRotateEnabled="True" IsTranslateEnabled="True" IsScaleEnabled="True" MinimumScaleRadius="1" MaximumScaleRadius="720"/>
</interactivity:Interaction.Behaviors>
</Image>
<Image Source="Images/Jellyfish.jpg" x:Name="image2">
<interactivity:Interaction.Behaviors>
<WP7:MultiTouchManipulationBehavior IsInertiaEnabled="True" IsRotateEnabled="True" IsTranslateEnabled="True" IsScaleEnabled="True" MinimumScaleRadius="60" MaximumScaleRadius="360"/>
</interactivity:Interaction.Behaviors>
</Image>
</Canvas>
</Grid>
Alternatively you can use Blend inserting a reference to the project MultiTouch.Behaviors.Silverlight.WP7 and then dragging the MultiTouchManipulationBehavior from the Assets section to the control to be touch-enabled:
Considerations
This one has been an interesting exercise in porting code written for Silverlight to Windows Phone: I had only to create a Windows Phone 7 project and add to it the code already available for the Silverlight version and all worked well quite quickly.
Limitations
At this time the behavior works only in the fixed Portrait orientation of Windows Phone: if you change to Landscape the manipulation doesn’t work well. I’ll have to investigate further and currently I don’t have a physical device to test (I’d really love to have a device to try it
).
Happy Silverlighting!
Silverlight 4, MEF and MVVM: loading different “MEF Modules” in the same Container
Today I’ve finally found some time to make modifications in the “MEF MVVM” project on Codeplex in order to:
-
create a new module using WCF RIA Services and dynamically load this it inside the “MEF module container” described in the previous post;
-
use the INavigationContentLoader interface and MEF Metadata to share the same container for the various “MEF Modules”;
-
use the new Cosmopolitan theme available for Silverlight Navigation applications;
-
refactor the code of the ViewModel base class using the one available in the latest Prism drops;
-
refactor unit tests inserting an apposite Mock service.

The source code is available for download on Codeplex.
Happy Silverlighting!






