Featured Posts

VS2010+SL3VS2010 beta + Silverlight 3 It keeps showing "Unable to Start Debugging. The Silverlight managed debugging package isn't installed".Finally the problem can be solved by installing Developer Runtime.

Readmore

An image in a post Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sed felis. Aliquam sit amet felis. Mauris semper, velit semper laoreet dictum, quam diam dictum urna, nec...

Readmore

Cash-Out Refinance For many, their homes are just not dwellings that protect them against rain, sun, and wind. But they are piggy banks, which can be used to raise some urgent money, even if...

Readmore

Saturday, May 31, 2008

0
Listbox

I've remembered one day, I am doing my Imagine Cup coding part in Silverlight.

Suddenly, List of check box, List of Radio Button , List of Pic with Description come across in my mind.

Then, I think of a good way to do so. After a moment, I have these ideas.

 

Let me briefly explain. I will use a stackpanel to store the items for each item in list. Then add the stackpanel into the list.

Let say we have a list of checkbox and a list of redio button.

It is easy for us to create the list like this.

[sourcecode language='csharp']
ListBox lb = new ListBox();
for (int i = 0; i <= 7; i++)
{
    CheckBox cb = new CheckBox(); 
    cb.Content = "Choice" + i.ToString();
    lb.Items.Add(cb);
    // Of course you can add some Event here for

[/sourcecode]

 

Case of Radio button  is the similar, so I dont explain so much here.

But for the case of Pic with Desc...

I will do like this.

[sourcecode language='csharp']
ListBox lb = new ListBox();
for (int i = 0; i <= 7; i++)
{
    Image Img = new Image();
    BitmapImage bi = new BitmapImage(); 
    string k = "pic" + i.ToString();
    TextBlock tb = new TextBlock();
    tb.Text = k;
    k += ".jpg";
    bi.UriSource = new Uri(k, UriKind.Relative);
    Img.Source = bi;
    StackPanel sp = new StackPanel();
    sp.Add(Img);
    sp.Add(tb);
    lb.Items.Add(sp);
}  
[/sourcecode]

Hope this can help more people to know more about Silverlight.

Live with Light!

Steve Wong (Hong Kong)

0 comments:

Post a Comment