OpenSource Silverlight 2.0 Controls and how to use them

As this announcement said, Silverlight 2.0 beta will be released sometime in Q1 and it will come out with a lot of enhancements and UI controls such as textbox, button and etc.But it wont’ come fast. We probably need to wait a lit bit longer to get that release. So, what would you do if you want to develop the silverlight application with Alpha release? You may probably need to develop your own custom silverlight controls or find the opensource controls which are contributed by other developers. Yes. This is what I’m doing for now. As you are one of my readers of my blog, I will share you some controls that I created and some controls that I found and tested in this article. I hope it will save a lot of your time (at least) .

I added the sourcecode of all controls in my sample because there are a few issues in some of the controls since people used the different version of Silverlight. I have fixed, tested and uploaded them for you all. However, you should thank to the original authors for their most valuable contributions and all credits go to them.

One more thing I gotta tell you is that you can’t expect too much from those controls since those are in too early stage. Some may have a few bugs, some may not be so ease to use and some are lack of properties supports and etc. Anyway, I hope you can at lease learn something from controls and will be able to inspire your own controls.

Download : Demo Silverlight project and all controls sourcecode

Contents

  • Freshy Toolbar
  • Vivekdalvi’s Toolbar
  • Silverlight ToolBar DotNetNuke site
  • Silverlight 2.0 Alpha SDK (Button Control)
  • Silverlight XP-style Button
  • Silverlight 2.0 Alpha SDK (Slider Control)
  • Silverlight 2.0 Alpha SDK (ScrollViewer Control)
  • Silverlight 2.0 Alpha SDK (Listbox Control)
  • Vivekdalvi’s Progressbar
  • Vivekdalvi’s Hyperlink
  • Silverlight Combobox Control
  • Silverlight Checkbox Control

Freshy Toolbar

This is the toolbar control that I created based on Vivekdalvi’s toolbar. After downloading the sample from this article, You can find the sourcecode of this control under Toolbars folder of SilverlightUIControls project (attached sample).

Freshy Toolbar

How to use it?

  • Add the SilverlightUIControls project in your solution file.
  • Add the code below in the base Canvas of your xaml file (e.g. page.xaml) that you want to load (not silverlight user control)
    xmlns:controls="clr-namespace:Silverlight.Samples.Controls;assembly=ClientBin/Silverlight.Samples.Controls.dll"
    
  • Add the code below in xaml file where you want to show that toolbar. (Note: You probably need to adjust the left, top, width and height properties of toolbar control to meet your need. )
    <controls:FreshyToolbar x:Name="Freshytoolbar"
    Width="500" Height="31"  Canvas.Left="20" Canvas.Top="70"
    />
    
  • The following code is for adding the toolbar items to the toolbar.
    FreshyToolbar freshytoolbar = (FreshyToolbar)this.FindName("Freshytoolbar");if (freshytoolbar != null) {
    freshytoolbar.ToolBarCollection.Add(new FreshyToolbarButton("Home", new Uri("http://michaelsync.net")));
    freshytoolbar.ToolBarCollection.Add(new FreshyToolbarButton("About", new Uri("http://michaelsync.net/about-2")));
    freshytoolbar.ToolBarCollection.Add(new FreshyToolbarButton("Guest", new Uri("http://michaelsync.net/guest-book")));
    }
    

Vivekdalvi’s Toolbar

This toolbar is created by Vivekdalvi from Microsoft. (I’m not sure whether this is his real name or not. I found that name with his photo in one comment so let me call him like that.)

Free and Opensource Silverlight Toolbar

It looks a lit bit strange. I’m not so sure why he created like that. But I’m sure that if you read the sourcecode, you will definitely get the way for inspiring your own custom toolbar or menu.

How to use it?

  • Follow step 1 to 3 from Freshy Toolbar sample
  • Put the line below in xaml file that you want the control to show.
    <controls:Toolbar x:Name="toolbar" Canvas.Top="190" Canvas.Left="20" Height="50" Width="500"/>
    
  • The following code is for adding toolitems to the toolbar.
    Toolbar _toolbar = this.FindName("toolbar") as Toolbar;for (int i = 0; i < 8; i++) {
    ToolbarButton tb = new ToolbarButton();
    string uri = "images/image" + (i + 1).ToString() + ".jpg";
    tb.Image = new Uri(uri, UriKind.Relative);
    tb.ToolTip = uri;
    //tb.Click += new EventHandler<EventArgs>(tb_Click);
    _toolbar.ToolBarCollection.Add(tb);
    }
    

Note: Here is the instruction from original author.

Silverlight ToolBar DotNetNuke site

This is the toolbar control for DotNetNuke users.

Silverlight ToolBar DotNetNuke site

Here is the original post for that control. As I’m not using DotNetNike, I didn’t add the sourcecode in my sample file. So, you will have to go and read the instruction about that toolbar.

Silverlight 2.0 Alpha SDK (Button Control)

This button control (including sourcecode) is released with Silverlight 2.0 Alpha SDK. It doesn’t look good that much but if you read the sourcecode then you will get the idea how to create your own button control for Silverlight application.

Silverlight 2.0 Alpha SDK - Button

How to use it?

  • Follow step 1 to 3 from Freshy Toolbar sample
  • Paste the following code in XAML file.
    <controls:Button Canvas.Top="480" Canvas.Left="20" Text="Button1" />
    <controls:Button Canvas.Top="480" Canvas.Left="150" Text="Button2" />
    <controls:Button Canvas.Top="480" Canvas.Left="280" Text="Button3" />
    
  • Run the application. That’s all.

Silverlight XP-style Button

This button is available to download from this link. It looks exactly like XP button. But there are a few issues with this button. (e.g: Width or height can’t be increased. or etc) For the time being, the sourcecode is not available but I asked the original author of this control. He said that he is implementing more features for that control and he will write the step-by-step guide for making this control in his blog. (Hey The Reddest! I’m waiting your article. )

Silverlight XP Button

How to use it?

You can read this article “How to use the custom control in Silverlight?” if you want to know how to use that control in your own project.

Silverlight 2.0 Alpha SDK (Slider Control)

This is the horizontal slider bar that come along with Silverlight 2.0 Alpha SDK. You can easily change the orientation at runtime. In my example, I used the sliderbar control with image control. If you move the slider then the opacity property of image will be changed. There is very important notes as below that you must read in that sample.

A slider needs to be provided a Range in order to be functional and show up on screen. Currently you can only do this in code-behind, not in XAML markup because there is no type converter support.

Slider bar - Silverlight Control
BTW, that photo looks cool, isn’t it? (Thanks to Phitar for that photo.)

How to use it?

  • Follow step 1 to 3 from Freshy Toolbar sample
  • Add the code in XAML file
    <controls:Slider x:Name="hSlider" Canvas.Top="580" Canvas.Left="140"  />
    
  • Specify the Range from cs file.
    hSlider.Range = new ValueRange(0, 11);
    hSlider.Value = 10;
    //vSlider.Orientation = Orientation.Vertical;
    hSlider.ValueChanged += new EventHandler(hSlider_ValueChanged);void hSlider_ValueChanged(object sender, EventArgs e) {}
    

Silverlight 2.0 Alpha SDK (ScrollViewer Control)

This is the Scrollviewer control for Silverlight application. This control is shipped with Sliverlight 2.0 Alpha SDK. What I did in my sample is that I created the big canvas with image in code. Then, add that canvas to the content property of ScrollViewer control. (I think there are some issues with calculating the height and width of canvas. )

ScrollViewer - SDK

Note: Thanks to lorna87 for this photo.

How to use it?

  • Follow step 1 to 3 from Freshy Toolbar sample
  • Add the scrollbar in XAML file
    <controls:ScrollViewer x:Name="scrollViewer1" ScrollableHeight="60" ScrollableWidth="2"
    Width="300" Height="300" Canvas.Left="20" Canvas.Top="950" />
    
  • then, you have to set something that you want to show in ScrollViewer to the content property of Scrollviewer. For the time being, you won’t be able to place any control inside the ScrollViewer tag. In order to solve this problem, there are two wordaround so far. 1) You can create the base canvas in XAML view and place all controls that you want in that canvas. Then, remove that canvas from the page at runtime and set it to the content of Scrollviewer control. This is the way which is used in SDK sample. 2) If you don’t want to do that, you can create all controls that you want on the fly. then, set it to the content of Scrollviewer. This is the way that I used in my sample. Actually, those two workarounds are so similar. So, you can choose either way.In my example, the following code is written in PageLoad event.
    Canvas canvasForScrollViewer = new Canvas();
    Image _img = new Image();
    canvasForScrollViewer.Width = 1200;
    canvasForScrollViewer.Height = 1200;
    _img.Source = new Uri("images/waferfall.jpg",UriKind.Relative);
    canvasForScrollViewer.Children.Add(_img);
    scrollViewer1.Content = canvasForScrollViewer;
    

Silverlight 2.0 Alpha SDK (Listbox Control)

This control is shipped with Silverlight Alpha SDK. It doesn’t look nice in original so that I made a few minor changes and make it look like that below.

Silverlight Listbox Control

How to use it?

  • Follow step 1 to 3 from Freshy Toolbar sample
  • Add the listbox control in XAML file.
    <controls:ListBox x:Name="listBox" Canvas.Top="960" Canvas.Left="400"  Width="200" Height="249"/>
    
  • Write the code in Constructor
    for ( int i = 0; i < 15; i++ )
    {
    listBox.Items.Add (ListItem (i));
    }
    listBox.UpdateItems ();
    
  • Add the following function
    static int colorCounter = 50;
    // The ListItem method creates and returns one FrameworkElement
    // Each call results in an element with a different background color
    // then the previous
    private FrameworkElement ListItem(int i) {
    // our FrameworkElement will be a Canvas
    Canvas canvas = new Canvas();
    canvas.Width = 200;
    canvas.Height = 31;// in it we add a rectangle...
    Rectangle rect = new Rectangle();
    Color color = Color.FromArgb(0xff, (byte)(colorCounter % 256),
    (byte)((colorCounter + 50) % 256),
    (byte)((colorCounter + 120) % 256));rect.StrokeThickness = 1;
    rect.Stroke = new SolidColorBrush (Color.FromArgb (0xFF, 0x84, 0x7E, 0x7E));
    rect.Width = 200;
    rect.Height = 31;
    rect.SetValue(Canvas.TopProperty, 0);
    rect.SetValue(Canvas.LeftProperty, 0);
    colorCounter += 21;
    canvas.Children.Add(rect);//... and some text
    TextBlock tb = new TextBlock();
    tb.Text = "Item" + i;
    tb.Height = 21;
    
    tb.SetValue(Canvas.TopProperty, 6);
    tb.SetValue(Canvas.LeftProperty, 50);
    canvas.Children.Add(tb);
    
    return canvas;
    
    }
    

Vivekdalvi’s Progressbar

This is another control created by Vivekdalvi.

Silverlight Progressbar Control

I fixed two issues in that control. If you run my example, you can click one of those buttons to change the progress color.

Vivekdalvi’s Hyperlink

This is also another control created by Vivekdalvi. I used it in my previous article.

Silverlight Hyperlink Control

Silverlight Combobox Control

I found this control from this link. The original control is written in Javascript and XAML. I changed that control to Silverlight 2.0 User control.

SDK - Silverlight Combobox

There are two issues in that controls. First, it won’t show the scrollbar in Itemlist. Second, if you click somewhere in Canvas while the combobox is opening, it won’t close. As I said earlier, you will get the idea about how to create combobox in Siliverlight. Plus, you will be able to use that control in your project with a few minor modification.

How to use it?

  • You can bind the combobox with list<string> as below.
    List<string> data = new List<string>();
    data.Add ("Michael Sync");
    data.Add ("Michelle");
    data.Add ("Lilian");
    data.Add ("Julia");
    data.Add ("Alice");
    
    combobox1.DataSource = data;
    combobox1.DataBind ();
    

Silverlight Checkbox Control

This is the modified version of Checkbox control created by one MVP. I converted this control to Silverlight 2.0 user control and added one feature which you can select to show “cross” (middle one) or “mark” (last one) in the checkbox.

Silverlight Checkbox

I think it would be great if we can some animations for hovering.

Conclusion

That’s all for now. Three more controls (Textbox, Radiobutton and Chart) will be coming soon. (Hey don’t forget to subscribe my feed.) Even though those controls are not so perfect, you will be able to use them in your silverlight project with very minium efforts before Microsoft release the Silverlight 2.0 beta. If you have cool Silverlight 2.0 controls (not Javascript), please let me know. If you found some issues and want to contribute the fixes that you made, please contact me. I’m really appreciate it. Thanks a lot for visiting my blog.

Strangest websites on the net

I started collecting the list of strangest websites on the net since last year. Now, I have quite a few links in my bookmark and decided to share them with you all today. Of course, those are not something that you should visit everyday but you know, if you were like me, you might want to visit once. Some of them are really crazy and I can’t think of any reason why they created like that. maybe, web hosting and domain registration is extremely cheap for them. Okay. let’s take a look what I got.

Contents

  • Another day, another word
  • The World’s Hightest Website (a CSS Experiment )
  • Longest Domain on the net (Letters only)
  • Longest Domain on the net (Numeric only)
  • The Last Page of Internet
  • Do websites need to look exactly the same in every browser?
  • IE-Haters
  • Deleted Images
  • Just Fu*king Google it

Another day, Another word

URL : http://anotherdayanotherword.com/

I found this site from Dreamhost (DHSOTM). It has only one word at the middle of the page. That word is changing everyday. That’s why that site is called another day, another word. Strange, hum? If you turn on the speaker, you will hear the voice too.

Another day, Another word

—————

The World’s Hightest Website (a CSS Experiment )

URL : http://worlds-highest-website.com/

highest.jpg

This website is the World’s Highest Website. Currently, it’s 18.939 kilometers high (that’s about 11.77 miles). The following is the some fine print and technical details.

For the rest of the crew, here’s some fine print. This website is a CSS experiment. Due to its nature, there are some accessibility limitations, but anybody just slightly experienced will understand. The technical and design principles of this site are simple:
* One HTML container;
* pure CSS styling;
* no workarounds, filters, or hacks.

Known, yet interesting issues:

* For the record – Gecko-based browsers like Firefox show an interesting behavior when you want to make the site any higher (than precisely 18.939583 kilometers, that is), namely by “shrinking” or “collapsing” its main container;
* Internet Explorer doesn’t accept internal references behind the real action, and it’s unclear if the container’s height really is 18.939 kilometers (though it’s damn high – or long – nonetheless).

If you can come up with fixes or an even higher element, the formatting of which is broadly supported, email info at worlds-highest-website.com. Most likely, there’s some reward. And otherwise, if it’s found, it’ll be used ;)

—————

Longest Domain on the net (Letters only)

URL : <link>

Can you guess who own the longest domain on the net? Google! of course. There are 63 characters in that domain. Why don’t you visit by clicking the link above? :)

Strangest website - Longest Domain Name on net

Longest Domain (Numeric only)

URL : <link>

Longest Domain (Numerice)

This is another site that has very very long domain. AFAIK, the max length of domain (without subdomain and surffix) is 6 but this domain name is 64 numbers. So, I’m really confused about that. maybe. it might be cuz of number. If it’s characters only then the max length might be 63. Please correct me if I’m wrong.

Note: Subdomains and domain suffixes are not included in consideration.

More ~

—————

The Last Page of Internet

URL : http://www.wwwdotcom.com/

Did you know that there is the last of Internet? :) Some of you might already know about that since I posted about this in my blog last year. I wonder why the owner of that site keep on paying the domain registration charges and hosting fees for that page. I got one thought when I saw this. There is a number of people who are making money online. At the same time, there are a lot of people who are willing to spend money online. :)

Last Page of Internet

—————

Do websites need to look exactly the same in every browser?

URL : http://dowebsitesneedtolookexactlythesameineverybrowser.com/

I found this site in Dreamhost (DHSOTM). There is a question in title and an answer at the middle of page. So simple but strange! :)

No

—————

IE-Hater sites

I think that there are a lot of people who really hate the Microsoft Internet Explorer. They spent their money to show their hates.

—————

Deleted Images

URL : http://www.deletedimages.com/

Deleted Images

This site collected unsharp, moved, blurry and unfocused pictures from people. So, you can upload your photos that you are about to delete from your camera.

UPDATED on Jan 06, 2008

Just Fucking Google It

URL : http://www.fuckinggoogleit.com/

Don’t forget to google before asking something in forum. :)

strange.jpg

That’s all for now. I will add more if I found some more sites. Yes, yes! You can also share me if you know some strange websites like above. Thanks. (Actually, there are three more sites in my list but when I check today, those sites are down.)

Goodbye, Netscape!

Netscape

According to the news from TechCrunch, Netscape Navigator will die on February 1, 2008 since the Netscape development team has only 0.6% market share among the browsers. It is so sad for that team but (in my very low opinion) it’s pretty good news for web developers (especially for Ajax/Javascript developers). If you were in web development, you know how hard to fix the cross-browser issues and the cost/time for making cross-browser web applications.

Goodbye, Netscape! I hope you can do better next time..