Nov 12 2010

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!


Oct 4 2010

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


Apr 12 2010

Microsoft Surface Toolkit for Windows Touch Beta available for download

The Microsoft Surface Toolkit for Windows Touch Beta is a set of controls, APIs, templates, sample applications and documentation currently available for Surface developers.

With the .NET Framework 4.0, Windows Presentation Framework 4.0 (WPF), and this toolkit, Windows Touch developers can quickly and consistently create advanced multitouch applications for Windows Touch PCs.

This toolkit also provides a jump-start for Surface application developers to prepare for the next version of Microsoft Surface. Use it to take advantage of the innovative Surface technology and user interface to develop your own rich and intuitive multitouch experiences for a variety of Windows Touch devices.”

Links:

Enjoy!


Feb 9 2010

Visual Studio 2010 and .NET Framework 4 Release Candidate available

Some useful links:

Enjoy!


Jan 7 2010

A Silverlight / Expression Blend behavior to add Multi-Touch Manipulation and Inertia

I’ve updated the behavior available in the Expression Community gallery adding Multi-Touch manipulation (translation, rotation and zoom) and inertia effects using code from the Surface Manipulations and Inertia Sample for Microsoft Silverlight.

To enable Multi-Touch in your code simply download the behavior from here, add the project “MultiTouch.Behaviors.Silverlight” to a Visual Studio solution and then enable the gestures in XAML:

<UserControl x:Class="SilverlightMultiTouch.MainPage"
...
xmlns:interactivity="clr-namespace:System.Windows.Interactivity; assembly=System.Windows.Interactivity"
xmlns:behaviors="clr-namespace:MultiTouch.Behaviors.Silverlight; assembly=MultiTouch.Behaviors.Silverlight"
...
>

<Canvas>
  <Image Source="Images/Desert.jpg">
     <interactivity:Interaction.Behaviors>
         <behaviors:MultiTouchManipulationBehavior InertiaEnabled="True" TouchRotateEnabled="True" TouchTranslateEnabled="True" TouchScaleEnabled="True"/>
     </interactivity:Interaction.Behaviors>
  </Image>

  <Image Source="Images/Jellyfish.jpg">
     <interactivity:Interaction.Behaviors>
         <behaviors:MultiTouchManipulationBehavior InertiaEnabled="True" TouchRotateEnabled="True" TouchTranslateEnabled="True" TouchScaleEnabled="True"/>
     </interactivity:Interaction.Behaviors>
  </Image>
</Canvas>

The MultiTouchManipulationBehavior also contains some dependency properties (TouchRotateEnabled, TouchTranslateEnabled, TouchScaleEnabled and InertiaEnabled) to enable the corresponding gestures.

The example contains Multi-Touch manipulations applied to some Image controls and a Smooth streaming player of the Silverlight Media Framework.

I’ve also posted to CodePlex a sample using WPF 4 based on the article “Introduction to WPF 4 Multitouch“ by Jaime Rodriguez.

Hope this helps and Happy Silverlighting!


Oct 19 2009

Visual Studio 2010 Beta 2 and updated Silverlight Toolkit available

Lot of news this week!

Visual Studio 2010 and .NET Framework 4 Beta 2 are now available for download here, Jeff Beehler has posted some useful info about this “go live” release.

The new Silverlight Toolkit October 2009 Release is also available on Codeplex featuring Visual Studio 2010 support and various improvements on existing components (like drag-and-drop for items controls).

Read these posts by Tim Heuer and Jeff Wilcox for more details and enjoy!


Mar 2 2009

XAML State of the Union – Feb 2009

In this excellent article, Rob Relyea describes the new features of XAML planned to ship in .NET 4.


Feb 3 2009

Delphi Prism Roadmap available

Click here to read the future plans for Delphi Prism, by Nick Hodges.


Jan 29 2009

ASP.NET MVC 1.0 Release Candidate Available

Click here to read the original post by Scott Guthrie.

Download link: http://go.microsoft.com/fwlink/?LinkID=141184&clcid=0×409


Jul 2 2008

CodeGear, Delphi and RIA development

Thanks to this post by Marco Cantù, I’ve found two interesting articles by Justin James about the future of the Embarcadero/CodeGear development environments:

 

Justin states that ”CodeGear’s .NET products are expanding in new directions, which include RIA development and targeting other platforms (through systems such as Mono)”.

Will we be able to write rich internet applications using Delphi and targeting both .NET and Mono platforms?