Introduction
This article demonstrate how can we create Accordian Control dynamically in
silverlight.
We can create accordion control in silverlight dynamically.
Step 1: Create Accordian Control dynamically
//Accordian Control
Accordion accor=new
Accordion();
accor = new
Accordion();
accor.Height = 223;
accor.Width = 200;
accor.VerticalAlignment =
VerticalAlignment.Top;
accor.HorizontalAlignment =
HorizontalAlignment.Center;
Color bgColor =
new Color();
bgColor.R = 0;
bgColor.G = 89;
bgColor.B = 192;
bgColor.A = 255;
//AccordionItem
AccordionItem
AcorItems = new
AccordionItem();
AcorItems.Header = "Customer";
AcorItems.Background = new
SolidColorBrush(bgColor);
AccordionItem AcorItems1 =
new AccordionItem();
AcorItems1.Header = "Emplyoee";
AcorItems1.Background = new
SolidColorBrush(Colors.LightGray);
AccordionItem AcorItems2 =
new AccordionItem();
AcorItems2.Header = "Customer Data";
AcorItems2.Background = new
SolidColorBrush(bgColor);
We can add any control in accordianItem as their content. Suppose we have canvas
control and
Image control.
//Canvas
Canvas canvas = new
Canvas();
canvas.Height = 200;
canvas.Width = 200;
Add this image in canvas using their LeftProperty and TopProperty.
//Image
Image image = new
Image();
image.Height = 70;
image.Width = 60;
image.Stretch = Stretch.Fill;
image.Source = new
BitmapImage(new
Uri("/DynamicAccordianControl;component/Images/emp1image.jpg",
UriKind.Relative));
image.SetValue(Canvas.LeftProperty,
42.0);
image.SetValue(Canvas.TopProperty,
15.0);


Join the conversation! Your thoughts help the community grow.