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.
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
}
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.
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);
}
Hope this can help more people to know more about Silverlight.
Live with Light!
Steve Wong (Hong Kong)