Articles → LIGHT SWITCH 2011 → Adding Controls Dynamically In Lightswitch 2011
Adding Controls Dynamically In Lightswitch 2011
Software Requirement
- Visual studio 2010 is installed on your machine.
- Visual Studio 2010 service pack 1 is installed on your machine.
- Microsoft Visual Studio Light switch 2011 is installed on your machine
Prerequisite Knowledge
- How to add screen in lightswitch?
- What is Created event in lightswitch?
- What is ControlAvailable event in lightswitch?
Creation Of New Screen
Click to Enlarge
Add Custom Controls In The Screen
Click to Enlarge
Click to Enlarge
Click to Enlarge
Register Controlavailable Event In Screen’S Created Event
partial void CreateNew_Created() {
// Write your code here.
this.FindControl("ScreenContent").ControlAvailable += new EventHandler < ControlAvailableEventArgs > (CreateNew_ControlAvailable);
}
Add Code In Controlavailable Event
void CreateNew_ControlAvailable(object sender, ControlAvailableEventArgs e) {
if (e.Control is StackPanel) {
StackPanel spanel = (StackPanel) e.Control;
HyperlinkButton lnk = new HyperlinkButton();
lnk.Content = "google";
lnk.NavigateUri = new Uri("http://google.com");
lnk.TargetName = "_blank";
spanel.Children.Add(lnk);
lnk = new HyperlinkButton();
lnk.Content = "rediff";
lnk.NavigateUri = new Uri("http://rediff.com");
lnk.TargetName = "_blank";
spanel.Children.Add(lnk);
}
}
Output
Click to Enlarge
Download