Programatically Add Listbox with Image and Text in Silverlight
Step 1) Add listbox to xaml.
Step 2) Upload images to Silverlight Project.
Step 4) Run the Application.
Step 1) Add listbox to xaml.
Step 2) Upload images to Silverlight Project.
Step 3) Add Listbox Items Programatically , it includes images(shown above and with text).
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Horizontal;
Image img = new Image();
img.Source = new BitmapImage(new Uri("india.jpg", UriKind.Relative));
img.Height = 50;
img.Width = 50;
TextBlock blk = new TextBlock();
blk.Text = "India";
blk.VerticalAlignment = System.Windows.VerticalAlignment.Center;
blk.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
panel.Children.Add(img); panel.Children.Add(blk); listBox1.Items.Add(panel);
panel = new StackPanel();
img = new Image();
img.Source = new BitmapImage(new Uri("australia.jpg", UriKind.Relative));
img.Height = 50;
img.Width = 50;
blk = new TextBlock();
blk.Text = "Australia";
panel.Children.Add(img); panel.Children.Add(blk); listBox1.Items.Add(panel);
panel = new StackPanel();
img = new Image();
img.Source = new BitmapImage(new Uri("america.jpg", UriKind.Relative));
img.Height = 50;
img.Width = 50;
blk = new TextBlock();
blk.Text = "america";
panel.Children.Add(img); panel.Children.Add(blk); listBox1.Items.Add(panel);
panel = new StackPanel();
img = new Image();
img.Source = new BitmapImage(new Uri("uk.jpg", UriKind.Relative));
img.Height = 50;
img.Width = 50;
blk = new TextBlock();
blk.Text = "UK";
panel.Children.Add(img); panel.Children.Add(blk); listBox1.Items.Add(panel);
panel = new StackPanel();
img = new Image();
img.Source = new BitmapImage(new Uri("sa.jpg", UriKind.Relative));
img.Height = 50;
img.Width = 50;
blk = new TextBlock();
blk.Text = "SA";
panel.Children.Add(img); panel.Children.Add(blk);
listBox1.Items.Add(panel);
Step 4) Run the Application.





No comments:
Post a Comment