I've published the code samples about my silverlight library.

  1. CollectionViewSource - /
  2. RadialPanel - /

Here you can find the samples index: http://silverlight.boschin.it/library

The samples require the .

Due to the success of my I've decided to repeat the experience writing another text about a Silverlight 2.0 argument.

This time I would like to explore the layout capabilities and I've created a RadialPanel control and included it into my (ver. ) published on codeplex.

This is the opportunity to write an article on how to implements a custom layout panel. During the article I speak about Layout but also about Attached Properties that are strongly connected to the layout argument.

Your feedback on the article and on my english writing are welcome.

Link: http://blog.boschin.it/articles/silverlight-radialpanel.aspx

I've published a new article on my main weblog explaining how to create a CollectionViewSource control in Silverlight 2.0. The article has been written in english to get in touch with a mor broader audience.

CollectionViewSource is a component originally developed for Windows Presentation Foundation and present in the System.Data namespace from the first release. Is is very useful to filter, sort and group data before it has binded to an user interface control. It work as a filter interposed between Data and consuming control and may be customized in a very easy way. Silverlight 2.0 does not have a similar class so I've worked hard to create this control to support my work and I've decided to release it under the CCPL license on codeplex (http://www.codeplex.com/silverlight).

The full explanation of its internal working is available at this address:

http://blog.boschin.it/articles/Improving-Silverlight-2.0-databinding-with-a-CollectionViewSource-control.aspx

Please leave a comment if you like this article. I hope it is written in a good english, but if you have some comments on this argument please feel free to contact me on my contact form: http://blog.boschin.it/contact.aspx

One of the missing things of Silverlight is the capability to handle mouse double click events. This problem apply not only to Silverlight 1.0 but also to Silverlight 2.0 Beta 1. Silverlight is rich about Mouse event handling but have two limitations. The first one is the missing right-mouse-button handling due to the presence of a contextual menu for configuration of the plugin. The second thing is the presence of mouse up and down left-button events but not of the click and double-click.

So, I decided to create a small class to handle this problem in a simply way. The class I created behave as a translator that receive mouse-up events and transform them in click/double-click. The only way to discriminate from single to double click is taking care of a brief timeout (300 ms) after the first incoming mouse-up event. If this timeout expires without another incoming mouse-up event we have to raise a click event. Instead, if a second mouse-up arrive we need to raise a double-click event.

Handling events in this way has a little bit problem. We need to receive an event and then wait for another event without blocking the caller and the user interface itself. With javascript I handled this problem using a setTimeout() that reset a flag and raise the correct event after the timeout. With Silverlight 2.0 we need to use a Thread because it is the only way to wait an event without blocking the main thread.

My MouseClickManager class handle the problem in this way. In the next code block I show the main methods of the class:

   1: /// <summary>
   2: /// Handles the click.
   3: /// </summary>
   4: /// <param name="sender">The sender.</param>
   5: /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
   6: public void HandleClick(object sender, MouseButtonEventArgs e)
   7: {
   8:     lock(this)
   9:     {
  10:         if (this.Clicked)
  11:         {
  12:             this.Clicked = false;
  13:             OnDoubleClick(sender, e);
  14:         }
  15:         else
  16:         {
  17:             this.Clicked = true;
  18:             ParameterizedThreadStart threadStart = new ParameterizedThreadStart(ResetThread);
  19:             Thread thread = new Thread(threadStart);
  20:             thread.Start(e);
  21:         }
  22:     }
  23: }
  24:  
  25: /// <summary>
  26: /// Resets the clicked flag after timeout.
  27: /// </summary>
  28: /// <param name="state">The state.</param>
  29: private void ResetThread(object state)
  30: {
  31:     Thread.Sleep(this.Timeout);
  32:  
  33:     lock (this)
  34:     {
  35:         if (this.Clicked)
  36:         {
  37:             this.Clicked = false;
  38:             OnClick(this, (MouseButtonEventArgs)state);
  39:         }
  40:     }
  41: }

In the HandleClick method we receive the incoming events. Probably the event handler of the MouseLeftButtonUp event simply call this method passing sender and arguments. In this method first of all we need to acquire a lock on a shared resource. This resource is the "clicked" flag that indicate if we are handling the first or second event. After acquiring the lock we have two choices. If the clicked flag is set to false we are handling the first click event so we need to set the flag and start a thread that will wait 300 milliseconds before reset the flag. So if the clicked flag has not been reset when we receive the second mouse-up then we are handling a double click event. 

This may appear simply, but it has a little drawback. When we need to raise the single-click event, we are running in a separate thread so we may incur in a cross thread situation and we need to marshal the thread context to the main thread itself to avoid this condition. This is a common problem in windows forms environment and also in WPF. To handle the problem we have to use the Dispatcher object. In this code snippet I show a brief example:

   1: /// <summary>
   2: /// Called when click occure.
   3: /// </summary>
   4: /// <param name="sender">The sender.</param>
   5: /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
   6: private void OnClick(object sender, MouseButtonEventArgs e)
   7: {
   8:     MouseButtonEventHandler handler = Click;
   9:  
  10:     if (handler != null)
  11:         this.Control.Dispatcher.BeginInvoke(handler, sender, e);
  12: }

"Control" is a reference to the control that we have to notify the event. So we will user the Control.Dispatcher.BeginInvoke() method to marshal the event. To use my class MouseClickManager you have simply to crate an instance passing a reference to the control that will receive the click/double click events. Than in the MouseLeftButtonUp event you will call the HandleClick method. The event handler connected to Click and DoubleClick events will be called appropriately.

The class has been designed to configure the the timeout lenght. Some experiments revealed that 200 ms is less, but 400 ms is too much because we will begin to feel the click event delay.

Download: http://blog.boschin.it/download/mouseclickmanager.zip (1 KB) 

Technorati Tag: ,

I've just published an issue on Microsoft Product Feedback Center about a strange behavior I've found in the last two days. I'm working with Visual Studio 2008, developing an AJAX Enabled application that use massive javascript code. I take advantage of new Visual Studio 2008 intellisense for Javaxript that applies to files using <reference> tags but I saw that using an embedded resource javascript library cause Visual Studio 2008 to lock exclusively the resource assembly and fail during compilation with this error:

Unable to copy file "obj\Debug\ClassLibrary.dll" to "bin\Debug\ClassLibrary.dll". The process cannot access the file 'bin\Debug\ClassLibrary.dll' because it is being used by another process.

I've include a reference to a test project I've prepared to reproduce the issue, so you may download and test the example and possibly convalidate yourself the issue in the .

Steps to reproduce without my test project is:

1) create a solution containing a classlibrary and a webapplication
2) create a embeddedresource.js file in the ClassLibrary and set it to Embedded Resource
3) add the WebResourceAttribute
4) create a referencing.js file in the WebApplication
5) insert a reference to the embeddedresource.js file like this: /// <reference name="ClassLibrary.embeddedjscript.js" assembly="ClassLibrary" />
6) save and close all files
7) open both javascript files
8) run the compilation with CTRL+SHIFT+B (rebuild all)
9) the error happen

Please take a moment to check my sample and please vote it on the feedback center if you get the same behavior.

Test Project: http://blog.boschin.it/download/referencebugtest.zip

Feedback page:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=328999

The application I wrote some months ago is now published in the BEST ITA Apps showcase through the MSDN Italy weblog. I put into this application all my knowledge about Silverlight 1.0 and ASP.NET AJAX.

The application has been write to support a realtime monitoring system that works with GPS informations send by the vehicles on a central server. It show the position and the duty of public transportation vehicles, with tools to display races delay and current status.

It has been build using a transparent Silverlight layer on a map, and receive pseudo-realtime data from an AJAX ScriptService. The data is updated every few seconds and the vehicles marker move on the map. The application take advantage of AjaxControlToolkit to give a better user experience where it is necessary to get input from the user, and use silverlight for the rendering of markers, and tracks.

I hope this may be a good example on how to use Silverlight in a real application.

Link: http://blogs.msdn.com/italy/archive/2008/02/05/best-ita-apps-selsystemweb-e-silverlight.aspx

Buon Natale 2007It is many time I do not post in this weblog due to heavy workload...

Now one day before Christmas I would like to wish you a Merry Christmas. I hope you will have a beautiful time with your relatives, enjoying during the Christmas time meeting people you never meet, doing things you never do, watching your children joy in the Christmas morning, and eating around the table with your best friends.

I don't know if you all celebrate the Christmas but if it is not I hope you will have also a beautyful time.

Besh wishes and Merry Christmas!

(I promise I return to post on this pages as soon as possible)

I'm back, finally from the TechEd 2007 I attended last week in Barcelona. This was my first time on an international conference and I have to be honest saying that the first few days I'm very disoriented because of the new environment, and because of the english speaking that I'm not really trained for.

So, during the conference this problems has become less important and I had a really wonderful staying, plenty of new informations, personal contacts and parties in the Barcelona nights. I've attended both my tecnology specific sessions and different technology sessions and I found that is is better to dedicate this days to deeply know arguments that during the normal working time it is non possible to study. The best sessione I attended at all was dedicated to Astoria Project (by Pablo Castro) and CardSpace (by vittorio Bertocci). Both this sessions are plenty of code-examples and gave me some useful information about the incoming ADO.NET Data Service and the claim-based autentication. The work the guys of this teams done is very wonderful.

The Astoria project enable our projects to share data across the network in a way similar to navigate a website. So if you are developing a bike catalog (as the samples shown...) you may access data in this way:

http://localhost/bikes.svc/Categories - give you the entire categories listing

http://localhost/bikes.svc/Categories!5  - give you the categories with 5 as primary key

http://localhost/bikes.svc/Categories!5/Products - give access to the products in the category wth 5 as primary key

This semantic enable to access resources easily also from javascript because Astoria outputs directly in JSON as well as XML. The Astoria services, created extending a WebDataService<T> abstract class are entirely based on Windows Commuication Foundation.

On the other side CardSpace, delivered with the Framework 3.0, in the incoming framework 3.5 will become very usable and easy to implement. Into the ASP.NET toolbox where will be a new Login WebControl supporting the CardSpace autentication that enable ASP.NET application to be integrated with claim based autentication in a breeze. Vittorio, an Italian working in the USA ad evangelist developer, has explained this argument in a very clear way using many examples like MembershipAPI integration with CardSpace. I promise to deeply study the argument when I've some time free...

There was many other sessions I attended; I was at the first session by Steve Swartz and Clemens Vasters and I'm very satisfied seeing them in a real cabaret-session that has introduced a very clear explanation about SOA from the Microsoft point of view. I've see also sessione on VSTS, Scrum, Virtual Earth and so on...

At the end of the conference I have to thanks all the people I know and that will be patient speaking in quiet-mode to enable me to understand them speaking. Now i'm on the way to became and english-enabled person so the next year this will be a more simple appointment.

Technorati Tag: ,

It seems I will have to virtually leave my country. Some days ago our government has approved a new law that will rule the internet information. It is a new way to obtain money from the Italian people, because this law will add a new Internet Tax for the people that want to publish informations like weblogs. Addictionally it seems will be the the rule to register itself in a ROC (registry of communications) and probably acquire a Publishing Manager, responsible of the contents published in the blogs that wil have to be subscribed in a registry of journalists... like a newspaper...

Yes, it's true. Our country is not a democracy... so probably i will have to leave my country if i would like to continue writing in my weblogs... :(

Technorati Tag: , ,

Often I ask myself why it does not exist a way to control the status of a timer control on client-side. The Timer is a client-side control, incapsulated as IScriptControl into a server-control, but its use is focused in raise asyncronous postbacks without the intervention of the user. But it is simply uncontrollable. After you set its interval and enable it on server side it is impossible to stop it on the client without raise a postback.

This is a bad thing in my opinion. There was a bunch of cases when you may have the need to stop/start the timer responding to a client event. So I decided to analyze the inner working of the control to find a way to solve this issue. And here is the result of my work.

Suppose to have a Timer oin a page, side by side with a Checkbox thats need to start/stop the temporized postback. The first step is to find a reference to the client component representing the Timer.

var timer = $find('<%= timer.ClientID %>');

the $find() function simply enumerate all the components registered into the page and returns the instance to the caller. Now here is how to write an event handler for the click event of the checkbox to enable/disable the timer:

var chkEnabled = $get('chkEnabled'); chkEnabled.onclick = function() { var timer = $find('<%= timer.ClientID %>'); timer.set_enabled(chkEnabled.checked); if (timer.get_enabled()) timer._startTimer(); else timer._stopTimer(); }

You may think to have simply to set/reset the enabled property, but watching at the timer client code you may see that this property is not directly linked with the start/stop of the timer. It is only a property to acquire the value of the server control property, like always happen with the IScriptControls. So you have to manually call the _startTimer() and _stopTimer() private methods for this action to have an effect.

Technorati tags: , , ,
More Posts Next page »