Monthly Archives: June 2009

Monthly Archives: June 2009

Resize image with Silverlight and FJCore before uploading to server

Posted on by Joe in Silverlight, WCF | 4 Comments

I have a Silverlight application which allows the user to select images from their local PC which are then uploaded to a server via a WCF Service. It is easy enough to resize the image once it gets to the server, but this would still mean that the full image is being sent over the wire. In Silverlight 2 there are no built in features that allow us to do the resizing at the client, but it can be achieved …

Enum description using reflection and extension methods

Posted on by Joe in C# | Leave a comment

I don’t take credit for this as it was written by another developer on the the project, but I thought it was good and worth writing about. On the current project I’m working on we use a lot of enumerations for statuses which are shown in drop-down lists and grids. It can get a bit ugly from a UI perspective when simply using the ToString method as enumeration values cannot have spaces and are usually shortened for ease of use …

Simple double click in Silverlight

Posted on by Joe in Silverlight | Leave a comment

I needed to pick up on a double click on an image in Silverlight but there is no event to handle this. It can be done quite easily using a DispatchTimer.  I am doing this for an image but you should be able to do it for any UIElement. First I have imported the System.Windows.Theading namespace where the DispatchTimer lives.  In the constructor of the User Control containing the image I have instantiated the Timer and set its interval to 200 …

Setting the SelectedItem in a Silverlight TreeView

Posted on by Joe in Silverlight | Leave a comment

I wanted to select a specific item in my Silverlight TreeView programatically.  Looking at the TreeView.SelectedItem property the setter is not public so it cannot be done this way. If you are simply adding TreeViewItems to the TreeView you can cast the item you want to select in the Items collection to a TreeViewItem and set the IsSelected property to true. The following example will grab the first item and set it to selected. If you are binding a list …

Disable enter submitting form with JavaScript

Posted on by Joe in JavaScript | Leave a comment

On a project I was working on I was asked to disable the enter key submitting the form.  Usually it would be better just to ensure that hitting enter performed the correct action but if you do want to disable this you can do so with JavaScript. I created a JavaScript function called disableEnterSubmit which takes in the event as a parameter as shown below. The event has different properties for the code of the pressed key for Internet Explorer and …

Xbox 360 – Project Natal – No controller gaming?

Posted on by Joe in Xbox 360 | Leave a comment

Microsoft have announced Project Natal for Xbox 360.  It boasts controller-less gaming with face and voice recognition.  Obviously influenced by the Wii, the concept video does look interesting.  As a fan of the Skate and Skate 2 games the use of full motion body capture could be cool when it comes to skateboarding games, or it could be a complete flop. Will have to wait and see…

Alert, confirm and input message boxes in Silverlight

Posted on by Joe in Silverlight | Leave a comment

To use alert, confirm and input message boxes in Silverlight you need to import the following namespace. You can then show an alert box by doing… Or a confirm dialog by doing… Or an input prompt by doing…

Passing a byte array to a WCF method from Silverlight – The remote server returned an error: NotFound

Posted on by Joe in Silverlight | 8 Comments

My Silverlight application calls a method to get an image from the server as a byte array. When adding my Service Reference the ServiceReferences.ClientConfig automatically generated the binding’s MaxBufferSize and MaxRecievedMessageSize as 2147483647 which is a lot bigger than I want to I changed them to 5242880 (5MB).  When the application calls the service to bring down an image these values are used to limit the size of the response message. I also set the MaxBufferSize and MaxRecievedMessageSize to 5242880 in the …

Set Silverlight Image Source from byte array

Posted on by Joe in Silverlight | 10 Comments

I’ve been playing around with Silverlight and WCF services and I came across the need to set the Source of an Image control in Silverlight from a byte array. I have a service method which returns an image from the server as a byte array which I want to show in the Silverlight application. My service method is simple and looks like this: In the Silverlight application I create a MemoryStream from the byte array, then a BitmapImage from the …

Wrapped Listbox items in Silverlight and WPF

Posted on by Joe in Silverlight, WCF | Leave a comment

I wanted to display a list of image thumbnails similar to how Windows Explorer does it so they are displayed horizontally and wrap onto the next line. The ListBox allows you to choose a template for the panel used to display items. The following XAML uses the WrapPanel for the ItemsPanelTemplate and gives the functionality I wanted. I have also disabled the horizontal scroll bar so the images wrap to the next line.