Silverlight

My MIX 10K entry – SilverCooler

I’ve entered the MIX 10K competition where the goal is to write an application using no more than 10KBytes of source code in Silverlight. I’ve decided to implement a cocktail selector application – strictly listing alcohol free cocktails only – using the web services I’ve previously built for a popular cocktail site, iCocktail.co.uk.

ICocktail.co.uk was built with Flash using XML services and since Silverlight is indeed as powerful as Flash implementation was quite an ease – my only problem was squishing in the 10K limit (thanks for Colin’s post on some tips on minifying the code). The application I’ve developed is the following:

SilverCooler - Gergely Orosz's entry for MIX 10K

If you like it, please vote for it on its the MIX 10K entry site.

One thing all people noticed when looking at the application at first is the cool “bouncing” effect of the cocktail name. In the flash version this was done by using an EaseOutElastic transition. Not surprisingly Silverlight has similar animation effects as Flash, these are called easing functions. To achieve the bouncing effect I only had to add the following code to the animations changing the width and height of the shape:

DoubleAnimation animation; // The animation changing width or height of the shape popping up
animation.EasingFunction=new ElasticEase(){ Oscillations=3, Springiness=1, EasingMode=EasingMode.EaseOut };

Oh, and if you’re in for some more drinks, check out iCocktail.co.uk as well!

Silverlight bug when drawing large paths

I’m working on creating a zoom effect for a Silverlight Path object. This effect is easy to implement: I just have to apply a ScaleTransform and and a TranslateTransform within a TransformGroup for the Path (scale it up and move it on the screen where the user clicked to zoom). However when reaching a certain zoom level I’ve noticed some weird behaviour: the Path was drawn in some random, sometimes inverse way.

I’ve tracked the behaviour down to the point to when it seems that the problem is not with ScaleTransform but with Paths above a certain size. I’ve created a simple example project to reproduce the problem. The source can be downloaded here.

What I’m doing is drawing a simple rectangle with 5 points:
11

The issue

And I start to redraw it in larger sizes and at the same time re-positioning it to stay in the center (so I’m basically doing a centre zoom effect):
21

However when the size of the path is about 65 000px (or 80 times the height of the LayoutRoot – I used 1280*1024 resolution with the LayoutRoot grid being about 770px) the shape is drawn incorrectly:
3

Read More…

File Upload in Silverlight – a Simple Solution

Recently I wanted to implement a very simple file upload component in Silverlight that uploads a single file and if possible shows upload progress. Having done some search I’ve found numerous examples but all of them seemed too complex for the simple task of uploading a file so I implemented a really lightweight solution. The source code can be downloaded from here: SimpleFileUpload_v2.zip

Uploading files in Silverlight

Uploading files is quite an easy one in Silverlight: it’s basically just a request made to another server and the file contents are passed in this request. A possible way of implementing this is by using the WebClient class:

private void UploadFile()
{
FileStream _data; // The file stream to be read
string uploadUri;
 
byte[] fileContent = new byte[_data.Length]; // Read the contents of the stream into a byte array
int bytesRead = _data.Read(fileContent, 0, CHUNK_SIZE);
 
WebClient wc = new WebClient();
wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
Uri u = new Uri(uploadUri);
wc.OpenWriteAsync(u, null, new object[] { fileContent, bytesRead }); // Upload the file to the server
}
 
void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) // The upload completed
{
if (e.Error == null)
{
  // Upload completed without error
}

Upload Progress Indicator

The above solution does the job of uploading the file well. However it does not indicate file upload progress at all: when uploading large files or when having slow internet connection this behaviour would be desirable.

Silverlight has no built-in way to monitor the number of bytes sent which means that the only way to indicate upload progress is sending the file to the server in multiple, smaller chunks. Of course this behaviour needs support from the server side as well.

The idea is that multiple calls are made to the server, every call submitting the next chunk of the file. On the server these chunks are appended to the file.

Read More…

First trip to Silicon Valley

In summer 2008 me and three friends representing Hungary as team DigitalMania took part in the Microsoft Imagine Cup competiton in the software design category – one of the largest student technology competitons in the world. The task was to design an implement a solution regarding an environmental issue. We focused on the water problem and created the prototype of a system that aimed to reduce water used for irrigation by taking account various factors such as soil moisture, weather forecasts and custom user defined rules. We used custom hardware (controlling the pipes) and .NET, ASP.NET and Silverlight to for the user interface while developing the solution.

90_0_2654065312_d8f1f1fa74_b

To test how the system would work in real life we first constructed a mathematical simulation and – after we’ve calculated that savings would be 10-15% even to the soil mositure monitoring system and far more for automatic systems we built a simulation table to monitor and demonstrate the same think in a micro environment.

Read More…

1 2 3 Scroll to top