Microsoft is going to launch the new Windows 7 operating system in October 2009. Currently the RC version is available online. As you know, Windows 7 came up with lots of goodies including better resource management, better performance, jumplist management, multitouch functionality & many more. Here I will discuss on developing a simple multitouch application using .Net 3.5 SP1.

Before doing anything you have to download the Windows 7 Multitouch API. You can download it from here. Extract the downloaded zip file to your local hard drive. Be sure that, you are using Windows 7 & you have a multitouch enabled screen to test it out.

Create a WPF application using Visual Studio 2008. This will automatically add a XAML file named Window1.xaml for you. Now add an image to your solution directory & insert it in the XAML. Now your Window1.xaml will look something like this:

<Grid>
    <Image Source="images/Hydrangeas.jpg"/>
</Grid>
Add RenderTransform to the image so that, we can scale or rotate the image properly. This will produce XAML similar to this:
<Grid>
    <Image Source="images/Hydrangeas.jpg" RenderTransformOrigin="0.5,0.5" Width="400">
        <Image.RenderTransform>
            <TransformGroup>
                <ScaleTransform x:Name="trScale" ScaleX="1" ScaleY="1"/>
                <RotateTransform x:Name="trRotate" Angle="0"/>
                <TranslateTransform x:Name="trTranslate" X="0" Y="0"/>
                <SkewTransform AngleX="0" AngleY="0"/>
            </TransformGroup>
        </Image.RenderTransform>
    </Image>
</Grid>
Use proper names when you are adding different types of transform to the transform group. It will be easier for you to handle it from the code behind file. Run your application. This will open up your Window with an image inside it. If you want to drag or rotate the image this will not work because we haven’t integrated the functionality yet. Add two project references i.e. “Windows7.Multitouch” & “Windows7.Multitouch.WPF” from the extracted zip folder to your solution. These are the managed API codes for multitouch application development. Go to your Window1.xaml.cs & be sure that following namespaces are already included. You may have to add some of them.
using System; 
using System.Windows; 
using Windows7.Multitouch; 
using Windows7.Multitouch.Manipulation; 
using Windows7.Multitouch.WPF; 
Create two private members inside your partial class:
// object of a .Net Wrapper class for processing multitouch manipulation 
private ManipulationProcessor manipulationProcessor = new ManipulationProcessor(ProcessorManipulations.ALL);

// boolean value to check whether you have a multitouch enabled screen 
private static bool IsMultitouchEnabled = TouchHandler.DigitizerCapabilities.IsMultiTouchReady;
Now inside the Window Loaded event write the following lines of code:
// check to see whether multitouch is enabled 
if (IsMultitouchEnabled) 
{ 
    // enables stylus events for processor manipulation 
    Factory.EnableStylusEvents(this); 

    // add the stylus events 
    StylusDown += (s, e) => 
    { 
        manipulationProcessor.ProcessDown((uint)e.StylusDevice.Id, e.GetPosition(this).ToDrawingPointF()); 
    }; 
    StylusUp += (s, e) => 
    { 
        manipulationProcessor.ProcessUp((uint)e.StylusDevice.Id, e.GetPosition(this).ToDrawingPointF()); 
    }; 
    StylusMove += (s, e) => 
    { 
        manipulationProcessor.ProcessMove((uint)e.StylusDevice.Id, e.GetPosition(this).ToDrawingPointF()); 
    }; 

    // register the ManipulationDelta event with the manipulation processor 
    manipulationProcessor.ManipulationDelta += ProcessManipulationDelta; 

    // set the rotation angle for single finger manipulation 
    manipulationProcessor.PivotRadius = 2; 
}
Write your logic inside the manipulation event handler implementation block. Here I will do rotation, scaling & positioning of the image. Here is my code:
private void ProcessManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    trTranslate.X += e.TranslationDelta.Width;
    trTranslate.Y += e.TranslationDelta.Height;

    trRotate.Angle += e.RotationDelta * 180 / Math.PI;

    trScale.ScaleX *= e.ScaleDelta;
    trScale.ScaleY *= e.ScaleDelta;
}
From the ManipulationDeltaEventArgs you can get various values & depending upon them you can implement your functionality in this block. TranslateTransform will position the image, RotateTransform will do the rotation & the ScaleTransform will resize the image. Run your project to test your first multitouch application.
Download Sample Application
Published by on under .Net | Tips
While working in Windows you have seen that, while focusing on any TextBox the entire text inside it has been selected. This is a default behaviour of Windows, but in WPF this behaviour is not present. For this you have to write code.

If you want to add the same behaviour in your WPF application then you have to register the TextBox.GotFocus event for each textbox inside your Window and in that event implementation you have to write the code to select all the text inside the focused TextBox, right? If you do like this, then you have to write so many event registration for each one of the TextBox.

 

 

Lets say, you have a single Window with 100 TextBoxs in it. In this case though you can write the event definition inside a single implementation but you have to register the event for 100 times. Now imagine the same behaviour for 10 Windows inside the same application. Here you have to write the event implementation for each and every Window & register the event for each TextBox. This will definately clutter your code.

So, how can you get the said behaviour in your WPF application? It is a simple trick inside your App.xaml.cs file. This will be a global event handler for any TextBox in your application. If you open your App.xaml.cs you will find a overridable method named "OnStartUp". Inside this register the TextBox.GotFocus event for every TextBox before calling the OnStartup method for the base class. After doing this trick, your OnStartup method will look like this:

 

 

protected override void OnStartup(StartupEventArgs e)
{
    EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
    base.OnStartup(e);
}

Here, the EventManager class will be responsible to register the event handler for all TextBox. So simple right? Now add the event handler implementation for the TextBox in the same class. This will look like this:
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
    TextBox tb = sender as TextBox;
    tb.Focus();
    tb.SelectAll();
}  
             
Now run your application with multiple Windows having multiple TextBox on them. Focus on any TextBox having some texts inside it. You will see the same behaviour has been added to all of your TextBox.
Published by on under Tips | WPF
MoXAML is an AddIn for Visual Studio to make your coding more productive for WPF and Silverlight Applications. By using this great power toy, you can code without giving more efforts. It has lots of features like beautifying the XAML code, Keyword Lookup, better comment support for XAML, automated Dependency Property creation and more.

You can also explore the features of XAML Power Toys. This will give you a extended power to design your XAML. This is really a good AddIn not only for the designers but also for the developers. You can create your ViewModel class, create ListView or Form for selected class, extract properties to style, option to generate x:Name for controls, grouping controls inside GroupBox and lots of other goodies. Check out the site for the latest features.

Mole is a tool that integrates with Visual Studio which lets you inspect the Visual Tree of your application, view and edit properties or data, view the XAML for selected elements and more. It allows unlimited drilling to objects and sub objects.

Snoop is a tool which you can use to hook to your running WPF application and browse the Visual Tree of the application. You can also inspect and edit the properties, inspect routed events and magnify sections in the UI and also debug binding errors.

Crack.Net is a runtime debugging tool for .Net desktop applications (both WPF & WinForms) just like Mole & Snoop. It allows you to go thru the managed heap of another .Net application, view all kinds of values on different objects and also manipulate them easily. You can also read the Crack.Net article.
Published by on under .Net | Silverlight
Microsoft released Silverlight 3 on 10th July 2009 as per the schedule. You can download the SDK, Visual Studio Tools & Blend from the following location:
Silverlight 3 came with the following features:
  • Out of Browser support
  • Network status check
  • Pixel Shader Effects
  • Bitmap APIs
  • Runtime themeing support
  • Enhanced control skinning
  • Support for System Colors
  • Bitmap Caching
  • Perspective 3D view
  • GPU hardware acceleration
  • Text animation
  • H.264 support
  • RAW audio/video support
  • Save File Dialogue
  • Wrap Panel, View Box, Dock Panel
  • Support for local fonts
  • Binary XML
  • Component caching & Scene caching
Published by on under .Net | Silverlight
Azure service platform is a cloud computing platform hosted in Microsoft data centers. This provides operating system & different set of development service which the developers can use to build their own web applications or enhance them directly in that platform. Without purchasing any upfront technology, developers can create their applications more quickly & easily in the cloud. They only need working knowledge in .Net Framework & Visual Studio Environment. Azure service currently supports native languages. In future it will support many more including Microsoft & Non-Microsoft languages. Once the coding is done, the developer can build & host the application in the cloud, so that end user will be able to run it over the internet.
Azure platform consists of Windows Azure, which is an Operating System to provide on demand computing, storage and management of cloud applications. In short, Windows Azure is an Operating System for the cloud computing platform designed for utility computing. It provides facilities to write, host or manage applications & store data on demand. The service layer consists of different services like: Live Service, .Net Service, SQL Service etc. which provides building blocks within the platform for the developers.
image
Published by on under Web |

Cloud computing is a dynamic style of computing in which virtualized resources are provided as a service over the internet. The users of cloud computing need not to worry about the capital expenditure and maintenance cost of hardware and software resources. They have to pay only what they are using. This can be of two types. User can either pay the provider based on the resources consumed during the time period or a time based subscription.

Published by on under Web |

Microsoft launched their new search engine named Bing (Kumo) on 28th May in Europe which went fully online on 3rd June. This search engine was designed to help people not only to quickly find anything over the internet but also to plan a trip or make a purchase decision. Using "Bing" the end user can find any information they need on their daily basis to accomplish their tasks. Bing categories results in different category, based on which the user can find relevant results more accurately.

imageimage

image image

You can find some Tips & Tricks on Bing.com at: http://www.labnol.org/internet/bing-tips/8931/

Published by on under News |

Google Wave is a project announced by Google on 28th May 2009 at the Google I/O conference is expected to release later in 2009. This will be a next generation email subsystem designed to merge email, instant messaging, social networking & wiki featuring strong spelling/grammar checking & automated translation between nearly about 40 different languages.

The term "Waves" described by Google as "equal parts conversation and document", means any authorized participant can reply anywhere in the conversation, they can edit or can add more participants during the conversation process. All the participants will be notified of changes or replies in all the waves they are actively participating & all the modifications will be seen at real time, letter by letter. Not only this, multiple participants may edit a single wave simultaneously in the same context.

imageThis ability of Google Wave will let user to create collaborative documents modified in different location with full modification history, which can be searched by an user to view/modify any changes just like wikis.

More information about this is available in Google Wave Site.

Published by on under News |

Microsoft has recently launched Visual Studio 2010 and .Net 4.0 Beta 1 with more expressive features. Some of them are mentioned below:

[New Language Support]
Visual F# is a new programming language which actually combines functional & object oriented programming to provide scalable language for .Net.

[Test Driven Development]
Visual Studio 2010 now offers greater support for test driven development where tests can be written before the actual code as an approach to the software design.

[Multi Targeting]
By using the multi targeting feature you can also create application of earlier version in new IDE of visual studio.

[Parallel Processing]
Using the new parallel extension of .Net 4.0 developers can create application which will scale efficiently as the number of cores & processors increase.

[Security]
The new framework improvements & expanded capabilities in the security model by simplifying the security policy. Now runtime support has been removed for enforcing the Deny, RequestMinimum, RequestOptional, and RequestRefuse permission requests.

[Performance]
.Net framework 4.0 beta 1 now provides improvement in the startup time and faster performance for multi threaded applications.

[Lazy Initialization]
By using this feature, the memory for an object is not allocated until it is needed. This improves the performance by spreading the object allocation across the lifetime of the application.

[In-Process Execution]
This enables an application to load & activate multiple version of the CLR inside the same process. Now you can run applications those are based on the .Net 2.0 & .Net 4.0 inside the same process.

[Profiler]
In the new framework you can now attach, run and detach profiling tasks at any point of time.

[Garbage Collection]
.Net Framework 4.0 now supports background garbage collection. In earlier frameworks it was a concurrent garbage collection.

[Collection & Data Structure]
- The new framework now includes BigInteger which supports all the standard numeric operation including the bit operation.
- It now supports self balancing SortedSet tree which sorts automatically after insert/delete operation.
- A new data structure named Tuple has been introduced in this framework which can hold an ordered set of heterogeneous items.

[Exception Handling]
The new CLR can now handle any exception regarding the corrupted state of the underlying operating system.

and more…

Published by on under .Net |

Recently, I was facing performance issue while working with huge data. I need to bind those data inside a panel as Custom User Control & want to change the properties multiple times in a second. When I used less no's of data it was working fine, but, when I tried with more no of data, my application starts crying. It was a real pain to the application to start while loading those records & unfortunately I didn’t get any solution to that.

After doing a lot of analysis with VirtualizingStackPanel concept that I shared in my previous post “What is Virtualizing StackPanel?” didn’t solve my problem which I was facing due to huge no of data.

Later, I found a very good post (“WPF: Adventures in Virtualization by Mike Taulty”) shared by Dr. WPF on implementing custom Virtual Panel, which actually resolved my problem.

Here you will find some very good articles on step-by-step implementation of Virtual Panel:

Those are very nice articles to implement the custom virtual panel step-by-step & after implementation of this panel, I noticed a huge performance improvement in my application. This really helped me while working with a huge records.

Now, come to the basic concept of this virtual panel. What it actually does. It loads all the records in a different thread & populate them in the UI as much as records that can be viewable in the screen. While scrolling, it actually creates new object of the elements by virtualizing the existing elements. So, only those objects will be in the memory which are available in the screen. The rest will go for a cleanup process. Hence, improving the performance more & more…. depending on the visible UI elements.

See a nice example in this location: http://blogs.msdn.com/jgoldb/attachment/8116217.ashx

Published by on under .Net | Tips

Virtualizing StackPanel generates container items when needed & throws them from memory when they are no longer in the view. When the panel has huge number of items, at that time there is no need to keep the extra items in memory which are not in view. This solves the memory problem.

If you are populating a huge number of items in any panel, then it is a better idea to use the Virtualization. But, due to throwing away of the extra items & recreating them when in view, costs some extra processing power when the Virtualizing StackPanel uses the default Standard Mode. To solve this issue, just change the virtualization mode to "Recycling". This is called as Container Recycling, which introduced in .Net 3.5 SP1 as a new feature.

By default, this recycling mode is turned off. To enable the container recycling, first turn on the Virtualizing StackPanel with “VirtualizationModeProperty” as “Recycling”.

<WrapPanel x:Name="wrpPanel" VirtualizingStackPanel.IsVirtualizing="true" VirtualizingStackPanel.VirtualizationMode="Recycling" />

You can also use GetVirtualizationMode() & SetVirtualizationMode() to get or set the current mode.

Published by on under .Net | SilverlightTips

DependencyProperty is set to enable declarative code to alter the properties of an object which reduces the data requirements by providing a more powerful notification system regarding the change of data in a very specific way. In .NET, there are two types of properties. One is the normal property & another is the DependencyProperty which has added functionality over the normal property.

Now, let us discuss on how to implement such DependencyProperty to give a powerful notification on data change:

First of all, implement the UserControl class from INotifyPropertyChanged interface:

public partial class MyUserControl : UserControl, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Create your own normal Property, lets say the name of the property is “Caption”.

public string Caption

    get { return GetValue(CaptionProperty).ToString(); } 
    set { SetValue(CaptionProperty, value); }
}

Now, register the DependencyProperty to the CLR by calling the Register method by passing the property field that you used to store the data in earlier step:

public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register("Caption", typeof(string), typeof(MyUserControl), new PropertyMetadata(string.Empty, OnCaptionPropertyChanged));

The name of the identifier field of the DependencyProperty will be same as you used in the property after appending “Property” at the end. In this example, our Property name is “Caption”, hence our identifier field name is “CaptionProperty”. Add the PropertyMetaData with default value & callback event handler within the Register method as mentioned in the above code. Mark the identifier as static & readonly so that this will be unique to the CLR.

Now, implement the OnCaptionPropertyChanged event handler:

private static void OnCaptionPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)

    MyUserControl myUserControl = dependencyObject as MyUserControl; 
    myUserControl.OnPropertyChanged("Caption"); 
    myUserControl.OnCaptionPropertyChanged(e);
}

private void OnCaptionPropertyChanged(DependencyPropertyChangedEventArgs e)
{
    txbCaption.Text = Caption;
}

The implementation of the DependencyProperty is complete. You can either call it from XAML:

<local:MyUserControl Caption="My First Dependency Property Example" />

or from Code behind:

MyUserControl myUserControl = new MyUserControl();
myUserControl.SetValue(MyUserControl.CaptionProperty, "My First Dependency Property Example");

Published by on under .Net | Silverlight

Splash Screens are always helpful while starting the application. At the time of loading application code & data from backend, it is always good to show a splash screen to the end user. It actually gives a look & feel of loading something and that time the user will see the first UI on his desktop. In .Net 3.5 SP1, this is really simple. Just do the following to add a simple basic splash screen to your application.

1. Create a PNG image & add it to your project. PNG images are better choice rather than BMP images because, they are lighter in size and you can also create a transparent PNG image.

2. Now right click on that image & click properties from the solution explorer of Visual Studio 2008 SP1.

3. Here you will find an option named “Build Action”. Select “SplashScreen” from the dropdown.

4. Save the project, build it & run the application.

Now you will see the image (Splash Screen) before rendering the actual application. After completion of rendering of the main window, the Splash Screen will automatically close. This way, it improves the startup experience of the WPF application.

Published by on under Tips | WPF

Microsoft provides a tool named “MakeCert.exe” which helps us to create a temporary SSL Certificate for development environment. This tool comes with Visual Studio & also with Windows SDK. If you installed Visual Studio, you can find it in this location: “C:\Program Files\Microsoft Visual Studio <VERSION>\SmartDevices\SDK\SDKTools”. If you installed Windows SDK, you will get it here: “C:\Program Files\Microsoft SDKs\Windows\<VERSION>\Bin”.

Now open Command Console (“cmd.exe”) & change your current directory to one of the location specified above. Type the following in Command Prompt & hit enter:

makecert -b 01/01/2009 -e 01/01/2020 -n "CN=Developers" -pe -r -sk "Microsoft Cryptographic Provider" -ss "Microsoft Cryptographic Store" c:\developerCertificate.cer

This will create a test certificate (valid from 01/01/2009 to 01/01/2020) named “developerCertificate.cer” in your ‘C’ drive, which you can use for development environment. You can change the validity period by changing the begindate (-b) & expirydate (-e). You can also change all the parameters specified above.

Here is the list of the parameters mentioned above:

Parameter Description
-b Begin Date
-e Expiry Date
-n Certificate Subject Name
-pe Mark Generated Private Key as Exportable
-r Configures MakeCert to create a self-signed root certificate
-sk Subject’s Key Container Name
-ss Subject’s Certificate Store Name
Published by on under Web |

Silverlight 3, though it is in beta stage, but it came up with lots of new features. Some of them are mentioned below:

  • Silverlight 3 now supports H.264 video formats & AAC audio formats. Now it also supports RAW audio/video pipeline
  • It now supports GPU Acceleration by adding a parameter (EnableGPUAcceleration = "true") in the Silverlight object
  • It now supports 3D functionalities. You can now add Perspective view to the element level
  • Various Effects has been introduced in Silverlight 3 using Pixel Shader API (e.g. Blur, DropShadow etc)
  • Various Animations (like: bouncing, transition) are now part of the Silverlight 3
  • A user can start a Silverlight out-of-browser "application" either by right-clicking on the Silverlight element or by clicking on a button within the application itself
  • Silverlight now supports custom dialogs. By using the SaveFileDialog you can now write contents outside the sandbox
  • It now supports local messaging across multiple silverlight plugins
  • XAP compression has been improved
  • Lots of new controls (like: DockPanel, WrapPanel, Label, ViewBox, TreeView, ExpanderControl, AutoCompleteBox) were added in this version. New controls in the Silverlight Toolkit are also available
  • DataPagination has been added in Silverlight 3
  • Using NavigationFramework you can now navigate to different view of the application. You can now integrate the browser back/forward functionalities with this framework
  • Binding of elements are now available by which you can update the UI without any code. Data validation in binding is also available in this release
  • AssemblyCaching is now available by which you can download the external assemblies only once & later you can use them from the cache. This will improve the application load time during next load
  • In Silverlight 3 Network monitoring API has been introduced, by which you can check whether the application is connected to the network or not
  • Now binary XML format is also supported in addition to the text XML which will improve the performance in the messaging area

Cheers :)

Published by on under Silverlight | Web

If you are migrating Silverlight applications that were created for the Silverlight 2 Beta 2 release or earlier to the final release of Silverlight 2, you are going to need to get the newest Silverlight 2 Tools for Visual Studio 2008 and recompile your project(s).

1. Get the newest version of Silverlight 2 Tools for Visual Studio 2008. You can get these tools from the SDK or online at Getting Started. You may have to uninstall any old tools before doing this install.

2. Open your old project (e.g. .csproj file). A dialog will come up notifying you that your project was created with an older version of Silverlight tools and asks you if you want to upgrade your project. Click the Yes button.

3. Open all of the HTML files and change:

· The Silverlight MIME type from application/x-silverlight-2-b1 or application/x-silverlight-2-b2 to application/x-silverlight-2.

· The Silverlight installation URL from http://go.microsoft.com/fwlink/?LinkID=108182 or http://go.microsoft.com/fwlink/?LinkID=115261 to http://go.microsoft.com/fwlink/?LinkID=124807.

When the XAP is served from a different domain than the host HTML page, Silverlight will validate that the MIME type (Content-Type response header) returned on the HTTP response is application/x-silverlight-app. You are required to add an entry for the Silverlight XAP MIME type to your .htaccess file — e.g. AddType application/x-silverlight-app xap.

Note IIS7 shipped with the right MIME type configurations for Silverlight XAPs. No action is required if you are using IIS7.

Published by on under Silverlight |