Silverlight Double Click

Silverlight doesn’t support double clicks as it’s just a by product of the net and is old fashion, well there is a simple way to overcome this, you will just see how simple it actually is.

On the page UserControl we set the following:

private long _lastTicks = 0; 

On the object that you want to double click just add the following:

this.Element.MouseLeftButtonDown += new MouseButtonEventHandler(mPlayer_MouseLeftButtonDown);

This puts a single mouse left down event on the object, so how can we use this to our advantage. Ok have a look at our method.

private void mPlayer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
 if ((DateTime.Now.Ticks – _lastTicks) < 2310000)
 {
   // double clicked so do something
 }
 _lastTicks = DateTime.Now.Ticks;

As you can see it’s actually quite simple so enjoy your double click ability in silverlight.

Advertisements

Silverlight Cross Domain Policy

I have this little silverlight application which asynchronously reads xml files from another website, which is controlled by my self. When developing all was working as expected the files where being read in and everything looked and worked great.

But when i pushed these onto the production environment what did i get an error saying that i couldn’t actually read the files and i was getting a security exception.

I did some looking and finally found out that it’s actually Silverlight blocking me from reading the files. Why is it blocking me from reading the files but the more i read i finally got a better understanding of why it’s being blocked. It all has to do with cross domain, i had to start thinking not a simple developer but as a system can i have access to this etc.

Finally found the solution and all i had to do was add my “crossdomain.xml” file to the website and it all worked, below is an example of the xml file:

<?xml version=”1.0″?>
<!DOCTYPE cross-domain-policy SYSTEM “http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd”&gt;
<cross-domain-policy>
<allow-http-request-headers-from domain=”*” headers=”*”/>
</cross-domain-policy>

Silverlight uses both it’s own “clientaccesspolicy.xml” and then falls back to the default “crossdomain.xml” file. I believe you should set it up to work with both silverlight and flash so using the crossdomain.xml file is recommened but this depends on your requirements.

This example just allows all requests to function. For more information you can read this very help full blog I found: http://timheuer.com/blog/archive/2008/04/06/silverlight-cross-domain-policy-file-snippet-intellisense.aspx

Hope this helps, later.