Windows Phone: Unzip / Extract Compressed Files for Silverlight

I’m don’t really understand why compress or zip function was not added to Silverlight or Windows Phone since the Silverlight package or Windows Phones xap file was actually a zip file. Windows Phone will need to unzip all file download from marketplace in order to install in the phone. While I’m looking for a third party library to unzip file in my Windows Phone app, I come across this REALLY small unzip utility for Silverlight, which re-use the existing functions in Silverlight to done the job. Great, this is just what I looking for and the best part of it, the size is really small. It is just a C Sharp file!

A very simple tutorial for REALLY small unzip utility for Silverlight was provided on his blog but I found a missing function in the code. The GetFileNamesInZip can’t be found by Visual Studio. After taking a quick look in the source file, I found out that the function name was changed to FileNamesInZip instead. Below are the same example but with corrected function name call instead.

private void LoadZipfile()
{
    WebClient c = new WebClient();
    c.OpenReadCompleted += new OpenReadCompletedEventHandler(openReadCompleted);
    c.OpenReadAsync(new Uri("http://www.mydomain.com/myZipFile.zip"));
}

private void openReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    UnZipper unzip = new UnZipper(e.Result);
    foreach (string filename in unzip.FileNamesInZip())
    {
        Stream stream = unzip.GetFileStream(filename);
        StreamReader reader = new StreamReader(stream);
        string contents = reader.ReadToEnd();
        MessageBox.Show(contents);
    }
}



Download REALLY small unzip utility for Silverlight  

by Ooi Keng Siang via Ooiks’s Blog

 

Silverlight Button MouseLeftButtonUp/Down Event

Last few days, I have been trying to use a Button as a drag and drop object in Silverlight 4, but the MouseLeftButtonUp and MouseLeftButtonDown event just won’t fire up no matter how I click on it. After some search, I found out that MouseLeftButtonUp and MouseLeftButtonDown event in Button is handle by Click event thus it won’t trigger MouseLeftButtonUp and MouseLeftButtonDown anymore.

One solution for this is to create an inherited Button class and override MouseLeftButtonUp and MouseLeftButtonDown event by setting Handled to false so that it won’t handle by Click event. While the other solution is to use other UIElement control instead of Button.

But I’m lazy to create a class just for this purpose and I need a Button control. After some search on MSDN, I found out that I can prevent Click event to handle MouseLeftButtonUp and MouseLeftButtonDown event by setting button’s ClickMode to Hover which was by default is Press. It’s work! With just a single line or a property set, I can enable back MouseLeftButtonUp and MouseLeftButtonDown event for button now.

Source: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.onmouseleftbuttondown.aspx

by Ooi Keng Siang via Ooiks’s Blog

Silverlight for “Smart” Programmer

Just came back from Imagine Cup Workshop (Northern Region) .  Although some accident happen yesterday and we are force to delay the workshop from Saturday to Sunday, but lucky the workshop went smooth today. Meet a lot of great Imagine Cup participants from UUM and USM. As I’m not really good in design (in fact, I’m suck on design), I was only in charge on a small part of the workshop only. Koekoe and Matt do all the great show while I’m sit there listening and learning with others too!

As I promise that I will share my slide with everyone, that is the reason why I write this post. Although I don’t think my slide is very useful for everyone especially those who already master Silverlight, but I think it might still be very useful to those who want to try Silverlight out or want to improve their Silverlight interface in short time.

Presentation Slide: Imagine Cup Workshop

by Ooi Keng Siang